-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturnTrueValues.js
62 lines (37 loc) · 1.22 KB
/
returnTrueValues.js
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
/* HW- fall cohort: week 1 day 2
Homework will help you practice loops, arrays, objects, and functions.
1. Create a function that returns the number of true values there are in an array.
const testArray = [ true, false, false, true, false, false, false, true, true, true, false ]
2. Write a function that receives a car object as an argument and outputs the cars make and model.
3. Write a function to get the first element in an array */ // shift + option + A
let arrBool = [true, false, false, true, false, false, false, true, true, true, false]
// USING ---- FOR OF -----
/* function returnTrueBoolean() {
let counter = 0;
for (trueValue of arrBool) {
if (trueValue) {
counter++;
}
}
console.log(counter)
}
returnTrueBoolean();
*/
// USING ---- FOR IN -----
/* function returnTrueBoolean() {
let total = 0;
for (i in arrBool){
arrBool[i] ? total++ : undefined
}
console.log(total)
}
returnTrueBoolean();
*/
// USING ---- FOR CLASSIC LOOP -----
function returnTrueBoolean() {
let total = 0
for (let i=0; i < arrBool.length; i++ ) {
arrBool[i] ? total++ : undefined
console.log(total)
}
returnTrueBoolean()