forked from truecodersio/JavaScript_Objects_Arrays
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (23 loc) · 833 Bytes
/
app.js
File metadata and controls
34 lines (23 loc) · 833 Bytes
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
// Exercise 1
/** Takes an array of numbers as a parameter and returns the sum value of each number in the array. */
const numbers = [2, 22, 12, 17, 18, 39, 129];
function arraySum(arr) {
let sum = 0;
arr.forEach(function (num) {
sum += num;
});
return sum;
}
let result = arraySum(numbers);
console.log(result);
//Exercise 2
const book = {};
book.title = prompt("What is the title of your favorite book?");
book.author = prompt("What is the author of your favorite book?");
book.pageCount = prompt("How many pages does your favorite book have?");
book.readCount = prompt("How many times have you read your favorite book?");
book.info = function () {
return `${this.title} by ${this.author} is ${this.pageCount} page(s) long, that has been read ${this.readCount}
times(s).`;
};
console.log(book.info());