Repository navigation
Expand file tree
/
Copy pathfunction-conversion.js
More file actions
65 lines (51 loc) · 1.78 KB
/
Copy pathfunction-conversion.js
File metadata and controls
65 lines (51 loc) · 1.78 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
const conversionAnswers = [];
// Take the commented ES5 syntax and convert it to ES6 arrow Syntax
// let myFunction = function () {
// console.log("Function was invoked!");
// };
let myFunction = () => console.log("Function was invoked!");
myFunction();
conversionAnswers.push(myFunction);
// let anotherFunction = function (param) {
// return param;
// };
let anotherFunction = (param) => param;
anotherFunction("Example");
console.log(anotherFunction("Example"));
conversionAnswers.push(anotherFunction);
// let add = function (param1, param2) {
// return param1 + param2;
// };
let add = (param1, param2) => param1 + param2;
add(1,2);
console.log(add(1,2));
conversionAnswers.push(add);
// let subtract = function (param1, param2) {
// return param1 - param2;
// };
let subtract = (param1, param2) => param1 - param2;
subtract(1,2);
console.log(subtract(1,2));
conversionAnswers.push(subtract);
// Stretch
exampleArray = [1,2,3,4];
// const triple = exampleArray.map(function (num) {
// return num * 3;
// });
// This function triples the numbers of whatever array it's passed.
const triple = array => array.map(num => num * 3);
console.log(triple(exampleArray));
conversionAnswers.push(triple);
//If you wanted triple() to be specific to exampleArray, see below:
// (I don't think that's the intention, but just in case, here it is.)
const tripleSpecific = () => exampleArray.map(num => num * 3);
console.log(tripleSpecific());
//console.log(conversionAnswers);
function showConversionAnswers() {
let answerSpace = document.getElementById("conversionSection");
answerSpace.innerHTML += "<br /><p><strong>Conversion Section:</strong> </p>";
for (let i=0; i<conversionAnswers.length; i++) {
answerSpace.innerHTML += conversionAnswers[i] + "<br \><br \>";
}
return true;
}