+ 2

If…else else if Statements

Please help me with what is wrong with my if…else/ else if code. Thank you. https://code.sololearn.com/WP9NoSKG511l/?ref=app

16th Feb 2022, 5:21 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
12 ответов
+ 3
Tahiti🍷Castillo As I understood till now your code should be like this just in few lines: One more question why did you use parseInt when you are entering string value? https://code.sololearn.com/WBmU7LCALQ0S/?ref=app
16th Feb 2022, 9:26 AM
A͢J
A͢J - avatar
+ 4
If there are multiple statements in an if or else block, enclose them inside a pair of {}. You didn't do that, that's why you're getting this error.
16th Feb 2022, 5:23 AM
Rishi
Rishi - avatar
+ 4
Tahiti🍷Castillo For multiline statement we should use {} And also you are checking variable before assigning element value which is also wrong there should be: rat = document.getElementById('rat'); if (rat != null) document.write(p); Also no need to write same thing inside every condition. document.write(p); is same inside every condition. You can write this after final else block.
16th Feb 2022, 5:28 AM
A͢J
A͢J - avatar
+ 4
Tahiti🍷Castillo I did something that might help you. Input the word "cancer" and it'll tell how it looks like. Maybe not what you wanted but you'll get an idea by looking at it https://code.sololearn.com/WHfV08chfkEY/?ref=app
16th Feb 2022, 7:39 AM
Rishi
Rishi - avatar
+ 4
A͢J Oh, my gosh! You fixed it! I can hardly wait to get off work and look over your code. What I did was read various website explanations of how to achieve the objective, and there was one that gave the parseInt code, which makes no sense now that I’m thinking about it, because there are no integers involved. Not sure why I overlooked that. Thank you. 🙏
16th Feb 2022, 4:43 PM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
+ 3
Rishi Only one pair of {} for the whole thing? Or individually? Thank you!
16th Feb 2022, 5:24 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
+ 3
A͢J If I don’t give the instruction inside each condition, then what goes inside each { } ?
16th Feb 2022, 5:53 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
+ 3
Tahiti🍷Castillo what do you want to do actually? What are you trying to do with the if else if block?
16th Feb 2022, 6:50 AM
Rishi
Rishi - avatar
+ 3
A͢J I’m just wondering why I agonized for hours, unnecessarily typing dozens of lines of JS code, only to find out it only required <25 lines. 😩 I guess this is part of the initiation into the tech world. 😁 Thanks again.
17th Feb 2022, 3:19 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
+ 3
Tahiti🍷Castillo It is natural in starting learning. That's why practice is more important. As much as you will do practice your thinking level would be increase.
17th Feb 2022, 3:29 AM
A͢J
A͢J - avatar
+ 2
Rishi A prompt should ask what is your zodiac animal. Entering the animal name triggers a description written to the doc/screen.
16th Feb 2022, 7:00 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
+ 2
Rishi Thank you. That makes sense. But the info I want to output is lengthy. I have whole paragraphs hidden in HTML that I want to display based on the input.
16th Feb 2022, 4:36 PM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar