-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharray.html
74 lines (64 loc) · 1.42 KB
/
array.html
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
<html>
<head>
<title>javascript array</title>
</head>
<body>
<script language="javascript">
var myArray=[];
var i=0;
while(i<5)
{
myArray.push(i);
i++;
}
document.write(myArray);
document.write("<br>");
//................for printing odd no using for loop.......................
var odd=[];
var j;
for(j=1;j<10;j+=2)
{
odd.push(j); //.push is used to insert value
}
document.write("odd no. are: "+odd);
document.write("<br>");
var a=[1,2,3,4,5];
var total=0;
var i=0;
while(i<a.length)
{
total+=a[i];
i++;}
document.write("total is: "+total);
document.write("<br>");
//..........generates fractional random no..........
function RandomNo()
{
return Math.random();
}
document.write(RandomNo());
document.write("<br>");
//...........integer random no.....................
function RandomN()
{
return Math.floor(Math.random()*10); //10 is multiplied for generating intteger between 1 to 9
}
document.write(RandomN());
document.write("<br>");
//..................generating random no. between a range.....
function randomRange(min,max)
{
return Math.floor(Math.random()*(max-min+1))+min;
}
var random=randomRange(5,15);
document.write(random);
document.write("<br>");
//............terniary operator................
function check(num)
{
return num>0 ? "positive": num<0 ?"negative" :"zero"
}
document.write(check(0));
document.write("<br>");
</script>
</body></html>