What did i do wrong ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
24th Oct 2017, 8:44 AM
Mert Ali Uzun
Mert Ali Uzun - avatar
2 Answers
+ 1
Firstly you cannot chain else statements. This doesn't even make sense conceptually. Imagine I say tests [0] = if(true) {do something} Tests[1] = if (![tests[1]) {do something else } Tests [2] = If (![tests 1]&&!tests[2]) {do something else} Test 3, indexed as [2] will never be true because the statement cannot be untrue and unfalse. Additionally, Else statements do not take a test condition. If you want to run a test use a "if" or "if else" condition. Only use an else to catch untested conditions because it checks that all tested conditions are false. "Else (x<0)" is not valid. Should be :"else if(x<0). Else statement test conditions is inbuilt. Its condition is whether all preceding if and else if statements are not true "!true". In addition the nested if statement is semi redundant. If x> 100 == true, x > 18 must == true. Thus x> 18 becomes redundant and just slows down your code. Also it makes your code less readable for no gain.
24th Oct 2017, 9:27 AM
josh mizzi
josh mizzi - avatar
0
You can cross check the error code here: https://gist.github.com/thomaslevesque/43e4950a65961e2194e4ce082d64bc31. I recommend you bookmark that page
24th Oct 2017, 10:05 AM
Teddy Okello
Teddy Okello - avatar