-
Notifications
You must be signed in to change notification settings - Fork 0
/
basics.js
101 lines (79 loc) · 2.11 KB
/
basics.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// this a comment
// operators arithmetic + - * /
// comparison == equality ===strict equality != inequality !== strict inequality <= >=
console.log("Hello world");
// VARIABLES - let const var
let f_name = "Raddames"; //string
let l_name = "Tonui";
let age = 40; // number
const school = "Moringa";
console.log("My name is "+ f_name );
// concatenation
console.log(f_name +" "+ l_name);
console.log("my name is "+ f_name +" "+ l_name +" and I am " + age +" and I am in "+ school );
// DATATYPES - string, number, boolean, undefined, null, , symbols, objects
// primitive & objects
// let fruits = [" oranges" , "mangoes", "pineapple" , "quavas"] // objects
let fruit = "apple";
console.log(typeof fruit);
console.log(typeof age);
let ismarried = true; //boolean
let children =false;
console.log(typeof ismarried);
console.log(Boolean(ismarried)); //boolean();
console.log(Boolean(children));
console.log("My name is "+ f_name +" "+ l_name +" and I am " + age +" MY Marriage is " + ismarried + " and children " + children );
// LOGICS
// ! NOT -negate a statement
let ischild = false;
console.log(!ischild)
// && AND
// Truth table
// T + T = T
// T + F = F
// F + F = F
// F + T = F
// // || OR
// T + T =T
// T + F = T
// F +T = T
// F +F = F
const truthyValue = 'This is a truthy';
let falseyValue = undefined;
console.log(Boolean(!0 && "false"));
//CONDITONAL STATEMENTS
// IF ELSE
age = 10;
if ( age <= 18)
{
console.log(" is child ");
}
else if ( age > 18 && age <=30)
{
console.log("is a youth");
}
else
{
console.log(" is an adult");
}
// SWITCH
let day = "Thursday"
switch(day){
case "Monday":
console.log("today is Monday")
break;
case "Tuesday":
console.log("today is Tuesday")
break;
case "Wednesday":
console.log("today is Wednesday")
break;
case "Thursday":
console.log("today is Thursday")
break;
case "Friday":
console.log("today is Friday")
break;
default:
console.log("Its a weekend");
}