Commit e97d860f authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

If / else statements

parent afd9ae29
...@@ -72,7 +72,7 @@ console.log(typeof x); ...@@ -72,7 +72,7 @@ console.log(typeof x);
/***************************** /*****************************
* Operator precedence * Operator precedence
*/ */
/*
var now = 2018; var now = 2018;
var yearJohn = 1989; var yearJohn = 1989;
var fullAge = 18; var fullAge = 18;
...@@ -94,4 +94,35 @@ console.log(x); ...@@ -94,4 +94,35 @@ console.log(x);
x += 10; x += 10;
console.log(x); console.log(x);
x--; x--;
console.log(x); console.log(x);
\ No newline at end of file */
/*****************************
* If / else statements
*/
var firstName = 'John';
var civilStatus = 'single';
if (civilStatus === 'married') {
console.log(firstName + ' is married!');
} else {
console.log(firstName + ' will hopefully marry soon :)');
}
var isMarried = true;
if (isMarried) {
console.log(firstName + ' is married!');
} else {
console.log(firstName + ' will hopefully marry soon :)');
}
var massMark = 78; // kg
var heightMark = 1.69; // meters
var massJohn = 92;
var heightJohn = 1.95;
var BMIMark = massMark / (heightMark * heightMark);
var BMIJohn = massJohn / (heightJohn * heightJohn);
if (BMIMark > BMIJohn) {
console.log('Mark\'s BMI is higher than John\'s.');
} else {
console.log('John\'s BMI is higher than Marks\'s.');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment