I need help | Sololearn: Learn to code for FREE!
+ 3

I need help

Yeah so I blindly tried to make a code where a prompt box pops up and if you enter the name (ÔÇťEthanÔÇŁ) it would say you did it and if you didnÔÇÖt it would say try again but itÔÇÖs not working so if someone could help me that would be nice. <html> <head> <title>Further Js</title> </head> <body> <script>var a =prompt ("Name"); if (a)= ("Ethan") alert ("You did it"); if else alert ("Try again"); document.write(a);</script> </body> </html>

5th Sep 2019, 8:28 PM
McBee
McBee - avatar
5 Antworten
+ 4
Good try, but there are a few points that need to be pointed out: - var a = prompt ("Name"); Good line, but don't put a space between prompt and ("Name); - If (a)= ("Ethan") The correct syntax for this is: if( [statement] ), so again the space between if and (. Also you don't need more than one set of brackets in if, just (a = "Ethan") is enough. Also I'd like to point out that === is rather used for checking strings than = - alert("You did it"); No mistakes, very nice - if else alert ("Try again"); If is not needed here. When you have used if() before, you could go to else if() or else, so just else is enough in this case. Also that tiny space between alert and ("Try again"); - document.write(a); Very good again and no errors in this line A few things I'd like to say after: - You might want a loop / repeating function when entering the wrong name - also try to look at spaces very cautiously - maybe even redo the javascript course, just to get things clear again Good luck Roel
5th Sep 2019, 8:50 PM
Roel
Roel - avatar
+ 2
Thanks a lot ­čśâ This will help a lot
5th Sep 2019, 8:52 PM
McBee
McBee - avatar
+ 2
No problem, hope it will help you learning
5th Sep 2019, 8:56 PM
Roel
Roel - avatar
+ 2
wow is it to esy No problem, hope it will help you learning
6th Sep 2019, 1:39 AM
Aaron.S.F
Aaron.S.F - avatar
+ 2
also document.write() is only good for testing code because it writes over html already written...and will only display what inside it...use alert(); console.log(); when debugging code. when manipulating DOM(document object model), use document.getElementById(); document.getElementsByClass(); document.querySelector(); document.querySelectorAll(); ,etc. etc. then .innerText=""; .innerHtml=""; or .textContent=""; etc.
7th Sep 2019, 7:04 AM
kay cruz
kay cruz - avatar