Repository navigation
Expand file tree
/
Copy pathpractice.js
More file actions
48 lines (38 loc) · 1.37 KB
/
Copy pathpractice.js
File metadata and controls
48 lines (38 loc) · 1.37 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
let check = true;
let mic = 'loud';
let balls = 200;
let myArr = [mic,balls];
myArr.push('apple');
console.log(myArr[0]);
console.log(myArr[1]);
console.log(myArr[2]);
console.log('now we iterate through the array');
for (let i = myArr.length - 1; i >= 0; i -= 1){
const addButton = document.getElementById('addopt');
const removeButton = document.getElementById('removeopt');
const checkButton = document.getElementById('checkbtn');
const textElement = document.getElementById('textcontainer');
textElement.innerHTML = myArr;
addButton.onclick = function(){
myArr.push('pear');
console.log('u pushed a pear')
console.log(myArr);
textElement.innerHTML = myArr;
}
removeButton.onclick = function(){
myArr.pop();
console.log(myArr);
textElement.innerHTML = myArr;
}
checkButton.onclick = function(){
if (myArr.length < 5){
console.log('there are less then 5 numbers in the array');
window.alert('there are less then 5 numbers in the array');
}
else if(myArr.length > 5) {
console.log ('there are more then 5 numbers in array');
window.alert('there are more then 5 numbers in the array');
}
}
}
console.log(myArr);