Can someone help me understand why my JS code is not properly executing? Sorry I am newer at coding. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Can someone help me understand why my JS code is not properly executing? Sorry I am newer at coding.

Below is my code - when I execute it, it does not return the proper birth year if the user enters a month greater than 9. However if I remove the else if code, it DOES properly execute and returns the proper year even if the user enters a birth month greater than 9. Would someone please be able to help me figure out what I'm doing wrong? var user = prompt("Please enter your name"); var user_age = prompt("Please enter your age"); var birth_month = prompt ("Please enter the number of the month you were born (ex. January = 1)."); if (birth_month > 9) {birth_year = 2019 - user_age} else if (birth_month == 9) {var birth_day = prompt ("Please enter the day of your birth")} if (birth_day > 13) {birth_year = 2019 - user_age} if (birth_day == 13) {var birth_hour = prompt ("Please enter the hour of your birth")} if (birth_hour > 8) {birth_year = 2019 - user_age } else (birth_year = 2020 - user_age) document.write ("Hello ", user, "! <br>"); document.write ("Your age is: ", user_age, ". <br>", "This means the yea

13th Sep 2020, 12:15 PM
Robert R.
Robert R. - avatar
3 Respostas
0
Sorry the end it cut off is just the output: document.write ("Hello ", user, "! <br>"); document.write ("Your age is: ", user_age, ". <br>", "This means the year of your birth is: ", birth_year);
13th Sep 2020, 12:17 PM
Robert R.
Robert R. - avatar
0
Copy into playground paste link here.. I think, you are not covering birthmonth is less than 9.. Last if part belong to that's previous last if...
13th Sep 2020, 12:38 PM
Jayakrishna šŸ‡®šŸ‡³
0
Document.write remove all previous context from document with what it have in it. I suggest you to use document. innerHTML += "...... text here...... " ; instead of document. Write Document. Write is used if you have to write only the things that is inside ( ) ; Also you have syntex error with various " Sorry the end it cut off is just the output: document.write ("Hello ", user, "! <br>"); // this šŸ‘† will not on screen only content of last document. Write will be there. document.write ("Your age is: "+user_age+ ". <br>"+ "This means the year of your birth is: "+ birth_year);
13th Sep 2020, 1:29 PM
Divya Mohan
Divya Mohan - avatar