-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
113 lines (60 loc) · 4.47 KB
/
index.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//ASSIGNMENT JAVASCRIPT BASICS AND NUMBERS. GOOD LUCK!
// INSTRUCTIONS - You need to fork this repl.it and then will turn in the new link to it that is created as your homework assignment once the work is completed
//NOTE ABOUT DEBUGGING your work console.log('any string here', varName) to console log values to see your answers before you run test.
//NOTE ABOUT TESTING your work. You should be able to test your answers by clicking into Shell on the right and typing 'npm test'. Question 6 will also need to be graded by hand, the test is not contain adequate coverage.
// QUESTION 1. Assign string values based on your own information to the variables firstName, lastName and homeCountry below.
const firstName = "Samantha";
const lastName = "Galindo";
const homeCountry = "Mexico";
// QUESTION 2. String addition - Add your firstName and lastName variables together and set them equal to the fullName variable as a string. Don't forget to add a space.
const fullName = firstName + " " + lastName;
//QUESTION 3. String Addition 2. - Create a sentence and set it equal to the mySentence variable that says "My full name is (your fullName variable). I am from (country)." Try and use string literal notation!
const mySentence = `My full name is ${fullName}. I am from ${homeCountry}.`;
//QUESTION 4. FUNKY INITIALS. Using multiple string methods and your firstName and lastName variables from above (think length, slice, indexOf, charAt, that kind of thing) programmatically place the last letter of your first name and the last letter of your last name into the funkyInitials variable below. Also make sure they are capitalized. Hint: You may want to create new variables as intermediary steps before finally setting or resetting the value of funkyInitials.
//let funkyInitials = "AO";
let AO = `${firstName.slice(7,8)} ${lastName.slice(6,7)}`;
let funkyInitials = AO.toUpperCase();
// QUESTION 5. Conditional 1 - We've had and have a lot of developers named Jorge at Code the Dream. So now we want to check programatically to see if you are the newest Jorge passing through the halls of CtD. Create an if/else statement that sets the variable isJorge to true if your firstName variable is "Jorge" and false if it is anything else.
//let isJorge;
let isJorge
if ("Jorge" === firstName){
isJorge = true
} else {
isJorge = false
}
//Question 6. Conditional 2 - You are given a randonNumber generator that will create a number between 1 and 3 in the randonNumber variable (do not change this code). Create a condtional where if the randomNumber variable is equal to 1 set theAnswer variable to "perhaps it is so", if randomNumber is equal to 2 set theAnswer variable to "yes, definitely" and if randomNumber is equal to three set theAnswer to "no, never"
/// DO NOT TOUCH THE CODE HERE - it is creating a random number between 1 and three for you to test against
const randomNumber = Math.floor((Math.random() * 3) + 1)
///// WRITE YOUR CODE BELOW
let theAnswer;
if ( randomNumber === 1 ){
theAnswer = "Perhaps it is so"
} if ( randomNumber === 2 ){
theAnswer = "Yes, definitely"
} else {theAnswer = "No, never"}
// QUESTION 7. Given the variable x, using JS round it to it's nearest two decimal number on the line immediately below the line that initially sets the x variable.
//noteforself: I don't quite understand what I am being asked to do ^^^^^
let x = 21.45729;
x = Math.round(x);
// QUESTION 8. Given the variable y as a string, convert it to the an integer with no decimal places. Round down.
let y = "15.3522";
y = Math.floor(parseFloat("15.3522"));
// OR using the Unary Plus Method y = Math.floor(+ "15.3522");
//QUESTION 9. Without removing the string delimitors from var1 (the " "), add var1 and var2 so that they add up to 42 as an integer and are stored in the variable var3.
const var1 = "24"
const var2 = 18
//code here
let var3;
var3 = +var1 + var2
//QUESTION 10 - MODULUS/REMAINDER and some other JS. If the variable var4q is divisible by exactly 6 then have the variable var4a set to the string "It is divisible." If it is not divisible by 6 then set it to the string. "I am not divisible."
const var4q = 42;
let var4a;
if (var4q/6) {
var4a = "It is divisible";
} else {
var4a = "I am not divisible";
}
// export functions and variables you want to check against here. Do not touch this if you are a student.
module.exports = {
theAnswer, firstName, lastName, homeCountry, fullName, mySentence, isJorge, funkyInitials, x, y, var1, var2, var3, var4q, var4a
}