In the “Build a Fortune Teller” lab (one of the hands-on coding exercises), it is VERY EASY to write completely broken code and still pass all the test.What happened to me:
I generated a random float between 1 and 5 (Math.random() * 4 + 1;)
Then I wrote the if/else chain using assignment (=) instead of comparison (===);
On the if/else chain I started with
if (randomNumber = 1) {...}, which will always be truth since it overwrites the value of the randomNumber variable to 1;
Result
The first fortune is always selected (5 fortune variables are created in the beginning of the exercise);
The random float (Math.random()) is never rounded to an integer
The code is fundamentally wrong in 2 different ways
All the test still passes
Here is my full code:
const fortune1 = "Your cat will look very cuddly today.";
const fortune2 = "The weather will be nice tomorrow.";
const fortune3 = "Be cautious of your new neighbors.";
const fortune4 = "You will find a new hobby soon.";
const fortune5 = "It would be wise to aboud the color red today.";
let randomNumber = Math.random() * (5-1) + 1;
let selectedFortune;
if (randomNumber = 1) {
selectedFortune = fortune1;
} else if (randomNumber = 2) {
selectedFortune = fortune2;
} else if (randomNumber = 3) {
selectedFortune = fortune3;
} else if (randomNumber = 4) {
selectedFortune = fortune4;
} else {
selectedFortune = fortune5;
}
console.log(selectedFortune);
This is really dangerous because the student walks away thinking they understood conditionals and random integers… when in reality they wrote a classic bug and the platform told them “Great job!”.
It teaches the exact opposite of what we want: it rewards a very common and hard-to-spot mistake.
I know automated tests are hard to get perfect, but this one is particularly bad because it silently accepts code that will fail in any real project.
Just wanted to make sure the curriculum/tech team is aware of this case.