+ 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
12 Respostas
+ 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
+ 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.
+ 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.
+ 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
+ 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. đ
+ 3
Rishi Only one pair of {} for the whole thing? Or individually? Thank you!
+ 3
AÍąJ If I donât give the instruction inside each condition, then what goes inside each { } ?
+ 3
Tahitiđ·Castillo what do you want to do actually? What are you trying to do with the if else if block?
+ 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.
+ 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.
+ 2
Rishi A prompt should ask what is your zodiac animal. Entering the animal name triggers a description written to the doc/screen.
+ 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.