/
LoopyLighthouse.js
70 lines (55 loc) · 1.75 KB
/
LoopyLighthouse.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
// MODUE 4: INTRO TO PROGRAMMING
//Assignment: LOOPY LIGHTHOUSE
/* We will be writing a program that prints the numbers from 100 to 200 to the console, with three exceptions:
If the number is a multiple of 3, print the string "Loopy" instead of the number.
If the number is a multiple of 4, print the string "Lighthouse" instead of the number.
If the number is a multiple of both 3 and 4, print the string "LoopyLighthouse" instead of the number.
By print, we are referring to console.log.
*/
//Use the % (modulo) operator to determine if a number is even or odd.
//The modulo operater takes two numbers and returns the remainder when the first number is divided by the second one:
/*
var number = 100
for (number = 100; number <= 200; number++) {
if (number % 3 === 0 && number % 4 === 0) {
console.log("LoopyLighthouse");
} else if (number % 4 === 0) {
console.log("Lighthouse");
} else if (number % 3 === 0) {
console.log("loopy");
} else {
console.log(number);
}
}
*/
let number = 100
for (number = 100; number <= 200; number++){
if (number % 3 === 0 && number % 4 === 0){
console.log("LoopyLighthouse");
} else if (number % 4 === 0) {
console.log("Lighthouse");
} else if (number % 3 === 0) {
console.log("Loopy");
} else {
console.log(number);
}
}
/* Not unlike the example from loops_Udacity for a while loop
ACTUAL SOLUTION (cleaner)
var x = 1;
// while loop with a stop condition
while (x <= 20) {
if (x % 3 === 0 && x % 5 === 0) {
console.log("JuliaJames");
}else if (x % 5 === 0) {
console.log("James");
}else if (x % 3 === 0) {
console.log("Julia");
}
else {
console.log(x);
}
// increment x at the end of each loop
x = x + 1 ;
}
*/