-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloops.js
87 lines (73 loc) · 2.01 KB
/
loops.js
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
//Loops Conditional Statements, Functions, Variables, Parameters
function forLoop(){
for (i = 1; i < 4; i++) {
document.getElementById('forLoop').innerHTML += "Hello World, ";
}
};
function whileLoop(i){
i = 3;
while (i < 4) {
document.getElementById('whileLoop').innerHTML +="Hello Planet, ";
i++;
}
};
function doWhileLoop(i) {
i = 1;
do {
document.getElementById('doWhileLoop').innerHTML +="Hello Solar System, ";
i++;
}
while (i <3);
};
function ifElseLoop(i){
i = 2;
if (i > 5) {
document.getElementById('ifElseLoop').innerHTML +="Hello Star, ";
}
else {
document.getElementById('ifElseLoop').innerHTML +="Hello Sun, ";
};
};
function ifElseIfLoop(i){
i = 5;
if (i < 3) {
document.getElementById('ifElseIfLoop').innerHTML +='Blue, ';
}
else if (i = 3) {
document.getElementById('ifElseIfLoop').innerHTML +='Black, ';
}
else {
document.getElementById('ifElseIfLoop').innerHTML +='Green, ';
};
};
var color1;
var color2;
function switchStatement(color1, color2){
color1 = 'Red';
color2 = 'Yellow';
switch(color2){
case 'Yellow':
document.getElementById('switchStatement').innerHTML +=('The color is ' + color1);
break;
case 'Red':
document.getElementById('switchStatement').innerHTML +=('The color is ' + color2);
break;
default:
document.getElementById('switchStatement').innerHTML +='There is no color.';
}
};
//Arrays, Associative Arrays
function firstArray(i){
var new_array = ['Leaf', 'Tree', 'Flower', 'Seed', 'Dirt', 'Water'];
for (i = 0; i < new_array.length; i++)
document.getElementById('firstArray').innerHTML +=('Array item ' + i + ' = ' + new_array[i] + ', ');
};
function assocArray(i){
var second_array = [];
second_array[0] = 'Fish';
second_array[1] = 'Shell';
second_array[2] = 'Sand';
second_array[4] = 'Water';
for (i = 0; i < second_array.length; i++)
document.getElementById('assocArray').innerHTML +=('Array item ' + i + ' = ' + second_array[i] + ', ');
};