if(js == "easy"){
console.log("Awesome !");
}
Comparison operator
- ==
- ===
- !=
- !===
- >
- <
- >=
- <=
Logical operator
- &&
- ||
- !
Conditional Statement
var allan = "kekar";
if(allan == "kekar"){
console.log("true block")
}
if(days >= 20){
// I am just statement / block
alert("sleep or die !");
}else{
// I am a function
goToWork();
}if(age >= 20){
console.log("adult");
}else if(age >= 5 && age >= 20){
console.log("teen");
}else{
console.log("baby");
}switch(day){
case 0:
console.log("happy day");
break;
case 1:
myBoringDay();
break;
default:
alert("Hello World");
}Looping
for(i = 0; i < 10; i++){
alert("Alerting you 10 times");
}for(i = 0; i < 10; i++){
if(i % 3 == 0){
alert("Multiplication of 3")
}else{
alert("Alerting you");
}
}for(i = 0; i < 10; i++){
console.log("i = "+i);
for(j = 0; i < 5; i++){
console.log("i inside another loop = "+i);
console.log("j = "+j);
}
}while(i < 99){
console.log("increment using while => "+ i);
i++;
}i = 10
while(i > 0){
console.log("increment using while => "+ i);
i--;
}do{
console.log("loop using do while => "+i);
i++;
}while(i < 10);Data types
- String
- Number (Integer & Decimal)
- Boolean
- Object
- Array
// to check type, use typeof followed by your parameter
typeof 123;var name = "Helmy"
var age = 26;
var normal = true;
var favorites = ["Coffee", "Tea", "Milk"];
var helmy = {name: name, age: age, normal: normal, favorites: favorites};
console.log(name);
console.log(favorites[2]);
console.log(helmy.age);
console.log(helmy.favorites[0]);Now please continue your calculator
js part 2
By Mukhammad Yunan Helmy
js part 2
- 491