-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.js
More file actions
91 lines (77 loc) · 2.5 KB
/
json.js
File metadata and controls
91 lines (77 loc) · 2.5 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
const { copyFileSync } = require('fs');
const { resolve } = require('path');
const readline = require('readline');
const input = readline.createInterface({
input: process.stdin,
output: process.stdout
})
var stCount = 6;
// Rough populations are in millions
CO = {"name": "Colorado", "capital": "Denver", "population": 5.7};
CA = {"name": "California", "capital": "Sacramento", "population": 39.5};
NY = {"name": "New York", "capital": "New York City", "population": 19.5};
VA = {"name": "Virginia", "capital": "Richmond", "population": 8.5};
TX = {"name": "Texas", "capital": "Houston", "population": 28.4};
FL = {"name": "Florida", "capital": "Tallahassee", "population": 21.2};
const lib = [CO, CA, NY, VA, TX, FL];
console.log("These are the states currently in the library: ");
printLibNames();
input.question('Which state would you like to retrieve from the library? (Enter full state name): ', (str) => {
getState(str);
input.question('Enter 0 for the state with the largest population and 1 for the smallest: ', (x) => {
if(x == 0){
getLargePop();
}else if(x == 1){
getSmallPop();
}else{
console.log("Incorrect Input");
}
input.question('Would you like to print the whole library? (y/n): ', (input) => {
if(input == 'y'){
printLib();
}else if(input == 'n'){
console.log("Have a nice day!")
}else{
console.log("Incorrect Input, we only print the library or nice messages for the correct inputs. (Get Lost)");
}
});
});
});
input.question('Which state would you like to add to the library? (Enter capitalized state abreviation): ', (addSt) => {
//addState(addSt);
console.log("Mark 1");
});
function printLib(){
for( let i = 0; i < stCount; i++){
console.log(lib[i]);
}
}
function printLibNames(){
for( let i = 0; i < stCount; i++){
console.log(lib[i].name);
}
}
function getState(state){
for( let i = 0; i < stCount; i++){
var x = lib[i].name;
if(x === state){
console.log(lib[i]);
}
}
}
function getLargePop(){
bigPop = 39.5;
for( let i = 0; i < stCount; i++){
if(lib[i].population == bigPop){
console.log(lib[i]);
}
}
}
function getSmallPop(){
smallPop = 5.7;
for( let i = 0; i < stCount; i++){
if(lib[i].population == smallPop){
console.log(lib[i]);
}
}
}