JS Module 2 — SolutionsJun 2026
Logic Brain Gym — Solutions
JavaScript, Logic, Solutions
Syifa Fauziyah Arizal
This page contains the official solutions for Module 2. If you haven't tried the challenges yet — stop scrolling.
Reading solutions without trying is like going to the gym just to watch people lift.
Challenge 1 — FizzBuzz
Rules recap:
- Multiple of 3 → Fizz
- Multiple of 5 → Buzz
- Multiple of 3 & 5 → FizzBuzz
JavaScript
let number = 15;
if (number % 3 === 0 && number % 5 === 0) {
console.log("FizzBuzz");
} else if (number % 3 === 0) {
console.log("Fizz");
} else if (number % 5 === 0) {
console.log("Buzz");
} else {
console.log(number);
}Why this order matters:
The combined condition must be checked first. Otherwise, JavaScript will exit early and your logic breaks.
Challenge 2 — Odd / Even Loop
Loop from 1 to 10:
- Even numbers → "Even"
- Odd numbers → "Odd"
JavaScript
for (let i = 1; i <= 10; i++) {
if (i % 2 === 0) {
console.log(i + " Even");
} else {
console.log(i + " Odd");
}
}This challenge checks three things: looping, modulo, and clean conditional thinking.
Challenge 3 — Login Simulation
Conditions:
- Correct username
- Correct password
- Error message if invalid
JavaScript
let inputUsername = "admin";
let inputPassword = "12345";
let correctUsername = "admin";
let correctPassword = "12345";
if (inputUsername === correctUsername && inputPassword === correctPassword) {
console.log("Login successful 👋");
} else {
console.log("Username or password is wrong ❌");
}This is a simplified version of real authentication logic. Same concept, different scale.
Bonus — More Detailed Validation
Cleaner feedback for users:
JavaScript
if (inputUsername !== correctUsername) {
console.log("Username not found");
} else if (inputPassword !== correctPassword) {
console.log("Wrong password");
} else {
console.log("Login successful");
}Same logic. Better UX.
