tenth day for full stack development -->> Javascript: variable type, Comparision operator, Take input by alert, Logical operator, switch statement, convert string to int, array and it's method.
// tell the variable type.
type of ("var");
==(double equal)
- check for equality of value, but not equality of type.
- It coerces both values to the same type and then compares them.
- this can lead to some unexpected results!
===(triple equal)
- strictly equal,
- check for equality of value, and also equality of type.
prompt to take the input from the user by the alert tab.\
prompt("enter the input") //return the string.
Logical operator.
&& (and operator)-->
truth && truth --->> output true
else it will be false
|| (or operator)
false|| truth---> Output true (any of condition is true then true)
false||false --> output false (both condition should be false )
Switch Condition
//define the function.
function week(day) {
//use of and operator
if (0 < day && day <= 7) {
switch (day) {
case 1:
console.log("monday");
break;
case 2:
console.log("tuesday");
break;
case 3:
console.log("wednesday");
break;
case 4:
console.log("thrusday");
break;
case 5:
console.log("friday");
break;
case 6:
console.log("saturday");
break;
default:
console.log("weekday");
break;
}
}
else {
day = parseInt(prompt("enter b/w 1 to 7"));
//recursive function
week(day);
}
}
//convert string to int
const day = parseInt(prompt("enter the week day no."));
//call the function
week(day);
//working with an array
//define the array
let colors=['red','orange','green','Yellow'];
//multidimensional array
let colorthings=[[black, hair],[white, teeth],[blue, eyes],[skin,brown]];
//change the value of array
colors[0]="red";
//array methods
let movieline=['tom', 'nancy'] //array
//1. Add the element in an array at the last of the array, if you don't know the index length of the array.
movieline.push('oliver')
//2. Remove the last element of the array, if you don't know the index length of the array.
movieline.pop()
//3. Add the element in an array at the first index.
movieline.unshift('olive')
//4. Remove the first element of the array.
movieline.shift()
//5. merge the two array
let colors=['red','orange','green','Yellow'];
let movieline=['tom', 'nancy']
let newarray= colors.concat(movieline); //the array name which is first use, will show first in new array
//6. tell whether the element is in the array or not
colors.include('green')//output:true, it always tell you the boolean value.
//7. tell the index of the value
colors.indexOf('green')//output :2 , tells the index of value from array.
//8. reverse the array
colors.reverse();
//9. break array in 2 parts
colors.slice(2,4)//break array in two-part and one 0 to 1 and other one is 2 to 4.
//10. delete, replace the element from the array from where you want.
colors.splice(1,2)//delete the 2 element from array after the index one.
color.splice(1,0,'red-orange')//add the value red-orange in the array.
Comments
Post a Comment