-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJS-challenge.js
More file actions
71 lines (54 loc) · 2.96 KB
/
JS-challenge.js
File metadata and controls
71 lines (54 loc) · 2.96 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Beginner Challenge */
/* Do all of these using proper ES6 syntax
Using the following array of objects,
(1) Write an arrow function that adds a new entry to bookList
(2) Write an arrow function that removes a specific book from the bookList
(3) Write an arrow function that lists out all the books or all the authors in the book list */
const bookList = [
{ title: "Don Quixote", author: "Miguel de Cervantes" },
{ title: "Ulysses", author: "James Joyce" },
{ title: "The Great Gatsby", author: "F. Scott Fitzgerald" },
{ title: "Moby Dick", author: "Herman Melville" },
];
// Beginner challenge code:
const addEntry = (title,author) => bookList.push({title,author});
const removeEntry = _title => bookList.splice(bookList.findIndex(find((index) => bookList[index] === {book,bookList[index][1]})));
console.log(bookList[0])
// test
addEntry("Outliers","Malcolm Gladwell");
removeEntry("Ulysses");
console.log(bookList);
/* Intermediate Challenge */
/* (4) Write a one-line arrow function that takes in a number and returns a string stating whether the
number is positive or negative using a ternary operator (assume the number will never be zero) */
let testNum = 1;
const posOrNeg = num => (num > 0) ? 'This number is positive': 'This number is negative';
console.log(posOrNeg(testNum));
/* (5) Write a switch statement for a 'day' variable that prints out something based off of what day of
the week it is
i.e. if it's Monday, print "good luck" or wednesday print "hump day" or friday print "party" */
/* (6) Write an arrow function that takes in a number, and uses a for loop to return the sum of every
number from 1 up to that number
ex. sumUp(7) = 28 */
/* Harder Challenge */
/* (7) Write an arrow function that converts the temperature from Celsius to Fahrenheit and then tells
me what I should wear accordingly */
/* (8) Write a function that takes in an array and prints out the amount of truthy values in that array
using .forEach() */
const exampleArray = ["Hello, world!", 8, null, false, "", "0", -22];
/* (9) Using the map function and arrow syntax, return an array of object that contain a fullName field
and an averageGrade field representing the letter grade that corresponds to their GPA */
const attendance = [
{ firstName: "Clay", lastName: "Tondreau", gpa: 4.0 },
{ firstName: "Tucker", lastName: "Wilson", gpa: 2.0 },
{ firstName: "Eliza", lastName: "Tobin", gpa: 3.7 },
{ firstName: "Sofia", lastName: "Ackerman", gpa: 1.1 },
{ firstName: "Thomas", lastName: "Beddow", gpa: 2.3 },
{ firstName: "Jackson", lastName: "Wolf", gpa: 4.0 },
{ firstName: "Jared", lastName: "Nguyen", gpa: 4.0 },
];
/* Hardest Challenge (Don't do this without completing harder challenges) */
/* Write a function that solves the "every number eventually equals 4" puzzle. The output should be
an array of the path you took to make it equal four
ex/ [11, 6, 3, 5, 4], [19, 8, 5, 4] or [252, 18, 8, 5, 4]
For context: https://puzzling.stackexchange.com/questions/29137/every-number-eventually-equals-4 */