-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
122 lines (94 loc) · 3.8 KB
/
Copy pathscript.js
File metadata and controls
122 lines (94 loc) · 3.8 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// question 1
// I created a variable called sayHello, and the value Hello world
var sayHello = "Hello world";
// question 2
// I created a variable called person, and gave it 2 properties. The keys is name and age, and the value is Karsten and 23.
var person = {
name: "Karsten",
age: 23
};
// question 3
// here I created a variable called outOfStock and assign it with a boolean value "true". I created an if else statement, that checks the value of outofstock. If it is true, it will output "Out of stock", if it is false, it will output "in stock".
var outOfStock = true;
if (outOfStock === true) {
console.log("Out of stock");
}
else {
console.log("In stock");
}
// question 4
// I made an array of five numbers and loop through the array and console log each value
var arrayOfFiveNumbers = [2, 3, 5, 7, 8];
for(var index = 0; index < arrayOfFiveNumbers.length; index++) {
console.log(arrayOfFiveNumbers[index]);
}
// question 5
// I made a for loop that starts at 15 and count each number up to 25
for(var counter = 15; counter <= 25; counter++) {
console.log(counter);
}
// question 6
// Here I used the same loop from question 5, and made it only log the value of the counter variabel if it is equal to 20
for(var counter2 = 15; counter2 <= 25; counter2++)
if (counter2 === 20){
console.log(counter2);
}
// question 7
// I created an array of two objects. I made that each object have the same three properties (with different values).
//I loop through the array and console log the number value and the boolean value
var users = [
{
name: "James",
age: 23,
male: true
},
{
name: "Jane",
age: 30,
male: false
}
];
for(var counter3 = 0; counter3 < users.length; counter3++){
console.log(users[counter3].age);
console.log(users[counter3].male);
}
// question 8
// I created a function called whatIDontLike that accepts one argument, I called the argument "dislikedItem".
// Inside the function I logged the string "I don´t like" together with the argument dislikedItem.
// I called the function whatIDontLike and passed in the string/value of "working".
function whatIDontLike(dislikedItem) {
console.log("I don´t like " + dislikedItem);
}
whatIDontLike("working");
// question 9
// I created a functions that accepts 2 argument, I called the arguments number1 and number2.
// Inside the function I subtracted the second argument from the first. And console log the result.
function mySubtractFunction(number1, number2) {
console.log(number1 - number2);
}
mySubtractFunction(3, 1);
// question 10
// I created an empty array. I created a functions called addToMyCakes and the function accept 1 argument. Inside the function I added the argument by using the variabel name and .push. I called the function and passed in "strawberrycake" as a string value.
var myCakes = []
function addToMyCakes(cake) {
myCakes.push(cake);
}
addToMyCakes("strawberrycake");
console.log(myCakes);
// level 2
// question 1
// Here I copyed the loop from question 5. And to find out what the modulus % operater was I had to google it. After a youtube tutorial I understood it. And wrote the code that makes it to display only even numbers. So when the number is equal 0 it will display because then it is a even number.
for(var counter = 15; counter <= 25; counter++) {
if (counter % 2 === 0) {
console.log(counter);
}
}
// question 2
// Here I made a variabel called innerFunction and made it equal a function, that logs the sentence "I am a function". Then I created another function called outerFunction. Inside the outerFunction I called the argument that I named myCaller. Then I called the function outerFunction and passed in the innerFunction variabel.
var innerFunction = function() {
console.log("I am a function");
}
function outerFunction(myCaller){
myCaller();
}
outerFunction(innerFunction);