here i am learning about another javascript inbuilt library function
For generating random numbers, we use
var randomno = Math.random(); //this creates random betw 0 and 1
to get a random whole number, we do
Math.floor(Math.random()*5 + 1); // this generates random whole number betw 1 and 5
** isNaN() : it checks to see if it is not a number
ex: isNaN(“berry”) here the output is ‘true’
There is also a ‘switch’ in javascript to avoid many if/else’s
The syntax is exactly like that of ‘C’ language
syntax
switch(expr){
case ‘option1’:
…..
break;
case ‘option2’:
…
break;
.
.
default:
..
break;
}
here ‘default’ is executed if there is no match in above cases
ex:
prompt(i);
switch(i){
case 1:
…
break;
case 2:
….
break;
default:
..
break;
}
don’t use {}, since we are already using break statement. Here javascript will try to match the expression between the switch() paranthesis to each ‘case’, if not there it will evaluate to ‘default’.
We also have logical operators just like in ‘C’ language
&& – for and operation
|| – for or operation
! – it makes a true expression false
**toUpperCase() function will convert all the input to capital letters
ex: “this is”.toUpperCase(); will give o/p ‘THIS IS’