Why doesn't my code work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why doesn't my code work?

Hello, I was trying to make a code but when executing it, an error comes out, someone who knows JavaScript tell me my error, I'm new, this is the code var Osito =(prompt("Responde solo con si o no: ")); if (Osito=Si) alert('Felicidades puedes ver') else if (Osito=no) alert('no puedes ver') else alert('Responde solo con si o con no')

27th Jan 2022, 8:27 PM
Miel De Abeja
6 Answers
+ 2
Miel De Abeja var Osito =(prompt("Responde solo con si o no: ")); if (Osito=='Si') alert('Felicidades puedes ver') else if (Osito=='no') alert('no puedes ver') else alert('Responde solo con si o con no')
27th Jan 2022, 9:01 PM
Mohammed
+ 3
let Osito = prompt("Responde solo con si o no: "); if (Osito!=null) Osito = Osito.toLowerCase().trim(); if (Osito=='si') alert('Felicidades puedes ver'); else if (Osito=='no') alert('no puedes ver'); else alert('Responde solo con si o con no');
28th Jan 2022, 12:08 AM
SoloProg
SoloProg - avatar
+ 1
Thank you Mohammed
27th Jan 2022, 10:29 PM
Miel De Abeja
0
The purpose of = is assigning. But == checks if they are the same or not.
27th Jan 2022, 8:34 PM
Mohammed
0
keeps giving error
27th Jan 2022, 8:45 PM
Miel De Abeja
0
Put Si inside quotes, 'Si', also for no, 'no'
27th Jan 2022, 8:47 PM
Mohammed