If else-statements | SoloLearn: Learn to code for FREE!

0

If else-statements

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

3/5/2020 6:16:20 PM

Zo Nelson

5 Answers

New Answer

+3

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.

0

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

0

Is the statement the numbers? How could I do that with words instead of numbers in order to get an outcome?

0

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.

0

simply xD if somthing happened....do this if not (else i mean)....do this