-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
87 lines (80 loc) · 2.68 KB
/
Copy pathcode.js
File metadata and controls
87 lines (80 loc) · 2.68 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
//pull info from data tables and put them into lists
var nameList = getColumn("Periodic Table Elements", "Name");
var abbrevList = getColumn("Periodic Table Elements", "Symbol");
var chargeList = getColumn("Periodic Table Elements", "Charge");
var diatomicList = getColumn("Periodic Table Elements", "Diatomic");
var metalList = getColumn("Periodic Table Elements", "Atom Classification");
var weightList = getColumn("Periodic Table Elements", "Atomic Weight");
var numberList = getColumn("Periodic Table Elements", "Atomic Number");
//creates variables that will be filled when the lists are filtered
var atomicNum = [];
var charge = [];
var fullName = [];
var diatomic = [];
var metal = [];
var weight = [];
//when the submit button is pressed, the user is directed to the result screen
//the lists are filtered and the result screen is updated
onEvent("submit", "click", function( ) {
setScreen("resultScreen");
updateScreen();
});
//sets screen back to the survey screen and clears the element input
onEvent("homeIcon", "click", function( ) {
setScreen("surveyScreen");
setText("elementInput", "");
setText("atomicNumberOutput", "");
setText("chargeOutput", "");
setText("nameOutput", "");
setText("metalOutput", "");
setText("weightOutput", "");
setText("diatomicOutput", "");
});
//filters the lists into the empty lists
function filter() {
//calls lists
nameList;
abbrevList;
chargeList;
diatomicList;
metalList;
weightList;
numberList;
//calls variables
var element = getText("elementInput");
atomicNum = [];
charge = [];
fullName = [];
diatomic = [];
metal = [];
weight = [];
for (var i = 0; i < nameList.length; i++) {
if ((abbrevList[i] == element || nameList[i] == element)) {
appendItem(fullName, nameList[i]);
appendItem(atomicNum, numberList[i]);
appendItem(charge, chargeList[i]);
appendItem(diatomic, diatomicList[i]);
appendItem(metal, metalList[i]);
appendItem(weight, weightList[i]);
}
}
}
//updates each element on the result screen
function updateScreen() {
filter();
if (charge.length > 0) {
setText("atomicNumberOutput", "Atomic #:" + atomicNum[0]);
setText("chargeOutput", "Charge:" + charge[0]);
setText("nameOutput", fullName[0]);
setText("metalOutput", metal[0]);
setText("weightOutput", "Weight:" + weight[0]);
if (diatomic[0] == true) {
setText("diatomicOutput", "Yes");
} else {
setText("diatomicOutput", "No");
}
} else {
setText("nameOutput", "We couldn't find your element");
setText("metalOutput", "Try again!");
}
}