Task 28: Javascript - Rinse and Repeat
Task 1: Variables
let name = "Enoch"; let age = 25;
console.log(name); console.log(age); β What will this print in the console?
π‘ Explanation: We declared two variables and used console.log() to output their values.
Task 2: Arrays
let fruits = ["apple", "banana", "cherry"]; console.log(fruits[1]); β What will be printed?
β Answer: banana
π‘ Explanation: Arrays are zero-indexed, so fruits[1] returns the second item.
Task 3: JSON Object
const student = { name: "Lukas", grade: 5, subject: "Math" };
console.log(student.subject); β What is the output?
β Answer: Math
π‘ Explanation: Weβre accessing the subject key from the student object.
Task 4: Loop (for loop)
for (let i = 1; i <= 3; i++) { console.log("Step", i); } β What will be printed?
π‘ Explanation: The loop runs 3 times, increasing i by 1 each time.
Task 5: DOM Manipulation
<p id="greeting"></p>
<script>
document.getElementById("greeting").textContent = "Hello, World!";
</script>
β What will be shown in the paragraph?
β Answer: Hello, World!
π‘ Explanation: We selected the paragraph by ID and changed its text content.