Skip to main content

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.