0

If else-statements

Could someone help me understand if else-statements and how it works? I am having trouble understanding them.

5th Mar 2020, 6:16 PM
Zo Nelson
Zo Nelson - avatar
7 Respuestas
+ 7
If and else statement If a > b : print yes else: print no The if and else statements are used to compare and contrast a statement. Print 'yes' if it's true and 'no' if it's false, like the example above.
31st Mar 2020, 8:31 AM
igwe chigozie
igwe chigozie - avatar
+ 3
It is very simple imagine someone selling You a pen . the sales man will ask do u want pen . your answer will be yes or no . Lets see this in code if( condition) { //if you want the pen document.write("yes"); } else { //otherwise document.write("no"); } like this you can use if else statement for this or that answers
20th Dec 2020, 9:31 AM
Shahidh
Shahidh - avatar
- 1
Is the statement the numbers? How could I do that with words instead of numbers in order to get an outcome?
5th Mar 2020, 6:44 PM
Zo Nelson
Zo Nelson - avatar
- 1
Zo Nelson , yes you can also check for strings values, Ex: let text="test"; if(text=="test"){ your instructions here }else{ your instructions here } Also as strings are case sensitive ,if(text=="Test") would be considered false... The best for you would be to play with differents type of value(numbers,string,Boolean) and to console.log the results to see what happen... You also have the challenges in sololearn which have such question and will help you understand,after challenge is completed go and check the answers.
5th Mar 2020, 11:39 PM
EmmanueLZ.
EmmanueLZ. - avatar
- 1
They are of c++
13th May 2021, 4:23 AM
kalyan durga reddy
kalyan durga reddy - avatar
- 2
An if statement runs if a condition is true and an else statements run if a condition is false eg. if(4>3){ document.write("true") } else{ document.write("false") } the output will be true because the condition in an if statement is true
5th Mar 2020, 6:41 PM
boolean
boolean - avatar
- 5
simply xD if somthing happened....do this if not (else i mean)....do this
5th Mar 2020, 11:49 PM
Ahmed Samy
Ahmed Samy - avatar