forked from ironhack-labs/lab-js-data-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
95 lines (62 loc) · 2.36 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
/*******************************************
Iteration 1.1 | Tongue Twister
*******************************************/
const s1 = "Fred";
const s2 = "fed";
const s3 = "Ted";
const s4 = "bread";
const s5 = "and";
// Concatenate the string variables into one new string
function tongueTwisterGenerator (wordArray) {
let tongueTwister ="";
for (i = 0; i < wordArray.length;i++) {
tongueTwister +=wordArray[i]+" ";
}
tongueTwister += `${s3} ${s2} ${s1} ${s4}`
return tongueTwister;
}
let wordArrayInitialised = [s1,s2,s3,s4,s5];
finalTongueTwister =tongueTwisterGenerator(wordArrayInitialised);
// Print out the concatenated string
console.log(finalTongueTwister);
/*******************************************
Iteration 1.2 | Camel Tail
*******************************************/
const part1 = "java";
const part2 = "script";
// Convert the last letter of part1 and part2 to uppercase and concatenate the strings
UppercaseConcattedString = part1.slice(0,3)+part1[3].toUpperCase()+part2.slice(0,5)+part2[5].toUpperCase();
// Print the cameLtaiL-formatted string
console.log(UppercaseConcattedString);
/*******************************************
Iteration 2.1 | Calculate Tip
*******************************************/
const billTotal = 84;
// Calculate the tip (15% of the bill total)
tipAmount=0.15*billTotal;
// Print out the tipAmount
console.log(tipAmount)
/*******************************************
Iteration 2.2 | Generate Random Number
*******************************************/
// Generate a random integer between 1 and 10 (inclusive)
randomNumber = Math.floor(Math.random()*10)+1;
// Print the generated random number
console.log(randomNumber);
/*******************************************
Iteration 3.1 | Booleans
*******************************************/
const a = true;
const b = false;
// Try and guess the output of the below expressions first and write your answers down:
const expression1 = a && b; //false
const expression2 = a || b; //true
const expression3 = !a && b; //false
const expression4 = !(a && b); //true
const expression5 = !a || !b; //true
const expression6 = !(a || b); //false
const expression7 = a && a; // true
expressionArray = [expression1,expression2,expression3,expression4,expression5,expression6,expression7]
for(i=0;i<expressionArray.length;i++) {
console.log(expressionArray[i]);
}