-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator-population.js
More file actions
97 lines (54 loc) · 3.47 KB
/
Copy pathcalculator-population.js
File metadata and controls
97 lines (54 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*** Population Calculator
/*** by Andrew Kramer
This program calculates what the population will be in 10 years from a current population of 412,000,000. It factors in a birth every 7 seconds, a death every 10 seconds, and an immigrant every 60 seconds.
*** PSEUDOCODE
- Create a variable named years and assign it a value of 10.
- Create a variable named birthrate and assign it a value of 7.
- Create a variable named deathrate and assign it a value of 30.
- Create a variable named immigrantrate and assign it a value of 60.
- Create a variable named currentpop and assign it a value of 412000000.
- Create a variable named yearsSeconds and assign the formulate of years * 31536000.
- Create a variable named birthSeconds and assign the formula of yearsSeconds / birthrate.
- Create a variable named birthsINT and assign it the parsed integer value of birthSeconds
- Create a variable named deathSeconds and assign the formula of yearsSeconds / deathrate.
- Create a variable named deathsINT and assign it the parsed integer value of deathSeconds
- Create a variable named immigrantSeconds and assign the formula yearsSeconds / immigrantrate.
- Create a variable named immigrantINT and assign it the parsed integer value of immigrantSeconds.
- Create a variable named futurepop and assign the formula currentpop + birthsINT - deathsINT + immigrantINT
- Create a variable named futurepopINT and assign it the parsed integer value of futurepop.
- Display currentpop and futurepopINT message.
*/
// Create a variable named years and assign it a value of 10.
let years = 10;
// Create a variable named birthrate and assign it a value of 7.
let birthrate = 7;
// Create a variable named deathrate and assign it a value of 30.
let deathrate = 30;
// Create a variable named immigrantrate and assign it a value of 60.
let immigrantrate = 60;
// Create a variable named currentpop and assign it a value of 412000000.
let currentpop = 412000000;
// Create a variable named yearsSeconds and assign the formulate of years * 31536000.
let yearsSeconds = years * 31536000;
// Create a variable named birthSeconds and assign the formula of yearsSeconds / birthrate.
let birthSeconds = yearsSeconds / birthrate;
// Create a variable named birthsINT and assign it the parsed integer value of birthSeconds
let birthsINT = parseInt(birthSeconds);
// Create a variable named deathSeconds and assign the formula of yearsSeconds / deathrate.
let deathSeconds = yearsSeconds / deathrate;
// Create a variable named deathsINT and assign it the parsed integer value of deathSeconds
let deathsINT = parseInt(deathSeconds);
// Create a variable named immigrantSeconds and assign the formula yearsSeconds / immigrantrate.
let immigrantSeconds = yearsSeconds / immigrantrate;
// Create a variable named immigrantINT and assign it the parsed integer value of immigrantSeconds.
let immigrantsINT = parseInt(immigrantSeconds);
// Create a variable named futurepop and assign the formula currentpop + birthsINT - deathsINT + immigrantINT
let futurepop = currentpop + birthsINT - deathsINT + immigrantsINT;
// Create a variable named futurepopINT and assign it the parsed integer value of futurepop.
let futurepopINT = parseInt(futurepop);
// Opening line break.
console.log("");
// Display currentpop and futurepopINT message.
console.log("The current population is", Intl.NumberFormat().format(currentpop) + ", and in 10 years the population will be", Intl.NumberFormat().format(futurepopINT) + ".");
// Closing line break.
console.log("");