forked from HackYourFuture/JavaScript1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditional_example_1.js
More file actions
33 lines (27 loc) · 892 Bytes
/
conditional_example_1.js
File metadata and controls
33 lines (27 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var code = 1;
let someOtherVariable = 'Hello';
const PROGRAM_NAME = 'conditional_test1.js';
let color = 'BLACK';
let age = Math.PI;
console.log(age);
console.log(age = '0'); // What will this line print?
console.log(age == 0); // What will this line print?
// The result of a logical operator like == === < > <= >= || && is a BOOLEAN (true, false)
console.log(age === 0); // What will this line print?
// === checks the TYPE and VALUE of the variable
if (code === 1) {
console.log("a " + color + ((age = 0 || age > 0) ? " used" : " new") + " car")
};
if (code === 1) {
console.log("a " + color + ((age <= 1 || age > 1) ? " used" : " new") + " car")
};
// Maybe simpler and easier to read?
if (code == 1) {
var carState;
if (age > 0) {
carState = " used ";
} else {
carState = " new ";
}
console.log("a " + color + carState + " car");
}