-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathq3-objects.js
More file actions
40 lines (33 loc) · 1.24 KB
/
q3-objects.js
File metadata and controls
40 lines (33 loc) · 1.24 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
/*
Task:
You are to convert the given two arrays (bookIdArr & bookTitle) into an object (booksObj) with four key value pairs:
- NLB1 -> Lord of the Rings
- NLB2 -> Programming for Dummies
- NLB3 -> Introduction to Software Testing
- NLB4 -> How to be a Software Developer
Tips:
- Use a for loop and utilizes the index variable as a running number.
- Be sure got use google!
*/
const bookIdArr = ["NLB1", "NLB2", "NLB3", "NLB4"];
const bookTitle = ["Lord of the Rings", "Programming for Dummies", "Introduction to Software Testing", "How to be a Software Developer"];
let booksObj = {};
function convert(keyArr, valueArr){
// Add code here
/*
Tips:
- Step 1: Create a local scoped object literal.
- Step 2: Define a for-loop that run based on keyArr's length.
- Step 3: Within the for-loop, add the key and value to the local scoped object.
- Step 4: Write a return statement to return the object literal after the for-loop code block.
*/
}
function printByKey(key){
console.log(booksObj[key]);
}
booksObj = convert(bookIdArr, bookTitle);
printByKey("NLB2"); // prints "Progamming for Dummies"
// Ignore the code below this line
module.exports = {
convert
}