+ 1

Why this code showing error??

I think the else-if syntax is right. Why it showing error. But if we use "if" instead of "else" it work, whyy?? The code 👇👇 https://code.sololearn.com/cm1h7e7SJDQb/?ref=app

19th Apr 2021, 12:47 AM
Jawad Ibrahim Shopnil
Jawad Ibrahim Shopnil - avatar
4 Respuestas
+ 2
Jawad Shopnil The appropriate formats are if if - else if - else if if - else if - else You can have as many 'else if' statements as you want/need after an if statement and before an optional else statement. The if statement requires a conditional as do all 'else if' statements, but an else statement will not use a conditional as it is used to cover all other conditions not checked for in a previous if or else if statement. Providing a condition for an else statement will result in an error. Please review the course lessons. if (condition) {...} if (condition) { ... } else { ... } if (condition) { ... } else if (condition) { ... } if (condition) { ... } else if (condition) { .... } else { ... }
19th Apr 2021, 11:36 PM
ChaoticDawg
ChaoticDawg - avatar
+ 4
else does not take a conditional expression. Remove (abc > 10) or add an if before it. else will take all cases that have not met one of the previous if or else-if conditions.
19th Apr 2021, 12:54 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
No condition is written in else you can use else if for the condition
19th Apr 2021, 3:28 AM
Atul [Inactive]
0
ChaoticDawg Can you explain more why else is not working, plzz.
19th Apr 2021, 10:09 PM
Jawad Ibrahim Shopnil
Jawad Ibrahim Shopnil - avatar