-
Notifications
You must be signed in to change notification settings - Fork 0
/
Udacity_JavaScript_Array.js
98 lines (86 loc) · 2.82 KB
/
Udacity_JavaScript_Array.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
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
/*
* Programming Quiz: Another Type of Loop (6-8)
*
* Use the existing `test` variable and write a `forEach` loop
* that adds 100 to each number that is divisible by 3.
*
* Things to note:
* - you must use an `if` statement to verify code is divisible by 3
* - you can use `console.log` to verify the `test` variable when you're finished looping
*/
var test = [12, 929, 11, 3, 199, 1000, 7, 1, 24, 37, 4,
19, 300, 3775, 299, 36, 209, 148, 169, 299,
6, 109, 20, 58, 139, 59, 3, 1, 139
];
// Write your code here
test.forEach(function(value,index) {
if (value %3 === 0) {
value += 100;
test.splice(index, 1,value);
} console.log(test);
});
var myArray = [1, 2, 3, 4, 5];
var newArray = myArray.map(functin(elem) {
elem = elem + 100;
return elem;
}
/*
* Programming Quiz: I Got Bills (6-9)
*
* Use the .map() method to take the bills array below and create a second array
* of numbers called totals. The totals array should contains each amount from the
* bills array but with a 15% tip added. Log the totals array to the console.
*
* For example, the first two entries in the totals array would be:
*
* [57.76, 21.99, ... ]
*
* Things to note:
* - each entry in the totals array must be a number
* - each number must have an accuracy of two decimal points
*/
var bills = [50.23, 19.12, 34.01,
100.11, 12.15, 9.90, 29.11, 12.99,
10.00, 99.22, 102.20, 100.10, 6.77, 2.22
];
var totals = bills.map(function(elem) {
elem += elem*0.15;
elem = elem.toFixed(2);
return Number(elem);
});
for (var row = 0; row < donumBox.length; row++) {
for (var column = 0; column < donutBox[row].length; column++ {
console.log(donutBox[row][column]);
}
}
/*
* Programming Quiz: Nested Numbers (6-10)
*
* - The `numbers` variable is an array of arrays.
* - Use a nested `for` loop to cycle through `numbers`.
* - Convert each even number to the string "even"
* - Convert each odd number to the string "odd"
*/
var numbers = [
[243, 12, 23, 12, 45, 45, 78, 66, 223, 3],
[34, 2, 1, 553, 23, 4, 66, 23, 4, 55],
[67, 56, 45, 553, 44, 55, 5, 428, 452, 3],
[12, 31, 55, 445, 79, 44, 674, 224, 4, 21],
[4, 2, 3, 52, 13, 51, 44, 1, 67, 5],
[5, 65, 4, 5, 5, 6, 5, 43, 23, 4424],
[74, 532, 6, 7, 35, 17, 89, 43, 43, 66],
[53, 6, 89, 10, 23, 52, 111, 44, 109, 80],
[67, 6, 53, 537, 2, 168, 16, 2, 1, 8],
[76, 7, 9, 6, 3, 73, 77, 100, 56, 100]
];
// your code goes here
for (var row = 0; row < numbers.length; row++) {
for (var column = 0; column < numbers[row].length; column++) {
if (numbers[row][column] %2 === 0) {
numbers[row][column] = "even";
} else if (numbers[row][column] %2 !== 0) {
numbers[row][column] = "odd";
}
}
}
console.log(JSON.stringify(numbers));