-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11-array-and-loops.html
More file actions
130 lines (106 loc) · 2.25 KB
/
11-array-and-loops.html
File metadata and controls
130 lines (106 loc) · 2.25 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8">
<title>Array and Lopps</title>
</head>
<body>
<script>/*
const myArray =[10 , 20, 30];
console.log(myArray);
console.log(myArray[0]);
myArray[0] = 99;
console.log(myArray);
[1,'hello', true, {name :'socks'},
[1,2,3]]
console.log(typeof [1,2]);
console.log(Array.isArray([1,2]));
console.log(myArray.length);
myArray.push(100);
console.log(myArray);
myArray.pop();
console.log(myArray);
console.log(myArray.splice(0,1));
console.log(myArray.splice(0,2)); */
/*let i=1;
while (i <= 5) {
console.log(i);
i++;
}
for(let i =1;i<= 5;i++)
{
console.log(i);
}
let randomNumber =0;
while(randomNumber < 0.5)
{
randomNumber = Math.random();
}
console.log(randomNumber); */
/*
const todoList =[
'make dinner',
'wash dishes',
'watch Youtube'
];
for(let i =0;i<todoList.length;i++)
{
const value =todoList[i];
console.log(value);
} */
/*
let nums= [1,1,3];
let total =0;
for(let i=0;i<nums.length;i++)
{
total+=nums[i];
}
console.log(total);
const numsDoubled = [];
for(let i=0;i<nums.length;i++)
{
const num=nums[i];
numsDoubled.push(num * 2);
}
console.log(numsDoubled);
*/
/*const array1=[1,2,3];
const array2=array1;
array2.push(4);
console.log(array1);
console.log(array2); // array2 is a reference to array1
//console.log(array1);that means only array two have just the address references of the array 1 not all the values of the array one.*/
//array2=array1.slice();
//const array3=[1,2,3];
for(let i=1;i<=10;i++)
{
if(i%3 ===0){
//continue;
break;
}
console.log(i);
}
let i=1;
while(i<=10)
{ if(i %3 ===0)
{i++;
continue;
}
console.log(i);
i++;
}
function doubledArray(nums)
{
// const nums =[1,2,3];
const numsDoubled = [];
for(let i=0;i<nums.length;i++)
{
const num=nums[i];
numsDoubled.push(num * 2);
}
return numsDoubled;
}
console.log(doubledArray([1,2,3]));
console.log(doubledArray([2,4,5]));
</script>
</body>
</html>