Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello im from Turkey istanbul im newbie in coding im on course, my teacher give me a exam but i dont know right answers, pls help me, sorry for my bad english.

Exam:Create two variables named a and b,

Assign the number 5 to variable a and 8 to variable b,

-As conditional programming, if variable a is less than 5, "add variable a and variable b", otherwise "subtract variable a from variable b"


this is my code but dont work:

var a
var b
a=5
b=8
if a<5 = a+b
else 5What I have tried:

var a
var b
a=5
b=8
if a<5 = a+b
else 5
Posted
Updated 20-Nov-21 8:26am
Comments
[no name] 20-Nov-21 13:56pm    
Addition and subtraction "usually" involves a 3rd variable: var c = a + b
CYBERCOMMANDO 20-Nov-21 13:59pm    
sir first thank you very much and second please extend the answer sir

1 solution

The syntax of your if statement is incorrect and a random "5" does not fit the instructions. Try
JavaScript
var c
If a < 5 {
   c = a + b
}
else {
   c = b - a

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900