Instructions:
- Create a new folder in
unit-2
calledreview-week-1
- Create an
index.html
file and areview.js
file. Link them! - Add a
console.log("review!")
toreview.js
- Preview your code in the browser with Dev Tools open
Then, for each of the following problems:
- predict what will happen.
- Then, run the code!
- Did you prediction match reality?
We'll do the first one together.
let x = 10;
console.log(x);
if (true) {
let y = 20;
var z = 30;
console.log(x + y + z);
}
console.log(x + z);
function sayItLoud() {
console.log(`${greeting}!!!`)
}
let greeting = "Hello!"
sayItLoud();
function sayItLoud() {
console.log(`${greeting}!!!`)
}
sayItLoud();
let greeting = "Hello!"
let greeting = "Hello!"
sayItLoud();
function sayItLoud() {
console.log(`${greeting}!!!`)
}
const isSunny = true;
if (isSunny) {
let status = 'No umbrella needed!';
} else {
let status = 'Better wear a raincoat!'
}
console.log(status);
const hour = 10;
function amOrPm() {
if (hour < 0 || hour > 23) {
return "invalid time";
}
if (hour < 12) {
return "am";
} else {
return "pm";
}
}
const test1 = amOrPm(10);
const test2 = amOrPm(14);
const test3 = amOrPm(20);
const test4 = amOrPm(25);
Remember, google is your friend! People often will copy and paste their errors to seek out help
function doubleArray(arr) {
debugger;
for (let i = 0; i < arr.length; i++) {
arr.push(arr[i] * 2)
}
return arr;
}
const result = doubleArray([1, 2, 3]);