0

I can only get either right or wrong but cant get both when i change the assignment operator to an equal operator. How do i fix?

function main() { var numberGuests = parseInt(readLine(), 10) if (numberGuests = "Even") { console.log("Right"); } else { console.log("Wrong"); } }

28th Nov 2020, 6:57 AM
Emmanuel Riano
Emmanuel Riano - avatar
13 odpowiedzi
0
using one “=“ is to assign a value “==“ is to evaluate without caring for the type “===“ evaluates caring for the type. var x = 1; var y = “1”; x==y is true x===y is false
28th Nov 2020, 8:10 AM
Jeremy Cruz
Jeremy Cruz - avatar
0
In other words, use “===“
28th Nov 2020, 8:10 AM
Jeremy Cruz
Jeremy Cruz - avatar
0
I tried that and it still only gets half right
28th Nov 2020, 9:29 AM
Emmanuel Riano
Emmanuel Riano - avatar
0
function main() { var numberGuests = parseInt(readLine(), 10) if ( numberGuests === "Even") { console.log("Right");} else { console.log("Wrong"); }}
28th Nov 2020, 9:29 AM
Emmanuel Riano
Emmanuel Riano - avatar
0
what is readLine returning?
28th Nov 2020, 9:30 AM
Jeremy Cruz
Jeremy Cruz - avatar
0
I have no idea i havent got that far in the lesson. The first 3 lines was already loaded do i need to delete it?
28th Nov 2020, 9:32 AM
Emmanuel Riano
Emmanuel Riano - avatar
0
write console.log(numberGuests) above the if statement so you can see the output.
28th Nov 2020, 9:34 AM
Jeremy Cruz
Jeremy Cruz - avatar
0
That just outputs numberGuests with the if statement.
28th Nov 2020, 8:36 PM
Emmanuel Riano
Emmanuel Riano - avatar
0
Entrance to the club is only permitted in pairs. Take the number of customers in the club as input, and, if all of them have a pair, output to the console "Right", otherwise output "Wrong".
28th Nov 2020, 11:14 PM
Emmanuel Riano
Emmanuel Riano - avatar
0
if(numberGuests % 2 === 0){ console.log(“right”); }else{ console.log(“wrong”); }
28th Nov 2020, 11:17 PM
Jeremy Cruz
Jeremy Cruz - avatar
0
numberGuests % 2 will take the remainder. if it is zero, right if it is more than zero, wrong.
28th Nov 2020, 11:18 PM
Jeremy Cruz
Jeremy Cruz - avatar
0
Thanks i got it now.
29th Nov 2020, 9:58 PM
Emmanuel Riano
Emmanuel Riano - avatar
- 1
Thats the original question.
28th Nov 2020, 11:14 PM
Emmanuel Riano
Emmanuel Riano - avatar