Https://www.codecademy.com/en/courses/introduction-to-javascript/0/2#

Getting error in this, could you guys spot the error
thanks in advance


//Here is an example of a strawberry index
var index = 20;

//Boolean value rotten
var rotten = false;

//If the index is divisible by five, the strawberry is rotten, so set
//rotten to true. False, otherwise

if (index % 5 === 0)
{
console.log('rotten =true');

}
else
{
    console.log('rotten = false');
    }
 


console.log() is a function to log something to the console (output window), why would you use it when setting a variable?

1 Like

= has a return value. It is perfectly valid to set a value and print it at the same time. Mind, as a string it is not code so nothing will happen but

rotten=true
 > console.log(rotten=true)
 true
=> undefined
 > rotten
=> true   
1 Like

Oh i get it, my mistake.

Thanks you the help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.