-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox.js
89 lines (71 loc) · 1.97 KB
/
sandbox.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
88
89
// //Data types
//STRING
let someName = 'Trevor';
someName += " S";
console.log(someName);
//Numbers
let someNumber = 27;
someNumber = someNumber + 3;
let someRemainder = someNumber % 3;
let someDividend = someNumber / 3;
console.log(someDividend, someRemainder );
//Non-primitive datatypes
//Objects
let rose = {
name: "rose",
color: "red"
}
let tulip = {
name: "tulip",
color: "yellow",
// gallonsOfWater: 1,
// someObject: {
// someKey: "someVariable"
// }
}
console.log("The beautiful " + rose.name + " is " + rose.color);
console.log("The beautiful " + tulip.name + " is " + tulip.color);
//Array
let listOfBookPages = [100, 270, 76];
let listOfBookTitles = ["Great Gatsby", "The Notebook", "IT"];
let listOfPlants = [rose, tulip];
console.log(listOfBookPages[0], listOfBookTitles[0], listOfPlants[0].name);
let pi = 3.14159;
pi += 8;
console.log(pi);
console.log("our very first javascript message");
//Iterations
let secondListOfBookTitles = ["Great Gatsby", "The Notebook", "IT"];
//push and pop
let myPoppedBook = secondListOfBookTitles.pop();
let anotherBook = "The Count of Monte Cristo";
secondListOfBookTitles.push(anotherBook);
// for loop
for(let i = 0; i <= 2; i++) {
let loggableString = secondListOfBookTitles[i];
console.log(loggableString)
}
// THIS WILL NOT WORK!! IT IS OUT OF SCOPE!!
//console.log(loggableString);
let numbers = [1, 3, 3214, 4564, 5, 78798];
for(let i = 0; i < numbers.length; i++){
let remainder = numbers[i] % 2;
//if remainder is 1 - it is odd
//else it is even
console.log(remainder)
if(remainder == 1){
console.log("ODD!")
} else if(remainder == 2){
//condition will NOT occur
}
else {
console.log("EVEN!")
}
}
let addNumbers = (number1, number2) => {
return number1 + number2;
}
let result1 = addNumbers(90, 34);
let result2 = addNumbers(234, 324);
let result3 = addNumbers(2, 5);
console.log("Our numbers: ", result1, result2, result3)