Day 6 — declarations, arrows, defaults
Hands-on
Topic 1 Part 1
function area(length, width) {
return length * width;
}
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 2 Part 2
console.log(area(10, 5));
console.log(area(7, 3));
console.log(area(15, 4));
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 3 Part 3
const areaArrow = (length, width) => length * width;
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 4 Part 4
console.log(areaArrow(8, 2));
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 5 Part 5
function greet(name = "Guest") {
return `Hello, ${name}!`;
}
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 6 Part 6
console.log(greet("Priya"));
console.log(greet("Aarav"));
console.log(greet());
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 7 Bonus
// Bonus
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 8 Part 8
console.log(greet(null));
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 9 Part 9
const cToF = celsius => (celsius * 9) / 5 + 32;
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 10 Part 10
console.log(cToF(0)); // 32
console.log(cToF(100)); // 212
console.log(cToF(37)); // 98.6
console.log(cToF(45)); // 113
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 11 Part 11
function double(n) {
return n * 2;
}
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 12 Part 12
console.log(double(2));
console.log(double(5));
console.log(double(10));
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 13 Part 13
let total = 0;
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 14 Part 14
function addToTotal(n) {
total += n;
return total;
}
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).
Section 15 Part 15
console.log(addToTotal(5)); // 5
console.log(addToTotal(5)); // 10
console.log(addToTotal(5)); // 15
Try the steps, then compare with ../js/hands-on.js (loaded at the bottom of this page).