You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: functions/studio/studio-functions.js
+52Lines changed: 52 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,13 @@
9
9
// 5. Use console.log(reverseCharacters(myVariableName)); to call the function and verify that it correctly reverses the characters in the string.
10
10
// 6. Optional: Use method chaining to reduce the lines of code within the function.
11
11
12
+
functionreverseCharacters(str){
13
+
returnstr.split("").reverse().join("")
14
+
}
15
+
16
+
console.log(reverseCharacters("apple"));
17
+
18
+
12
19
// Part Two: Reverse Digits
13
20
14
21
// 1. Add an if statement to reverseCharacters to check the typeof the parameter.
@@ -17,6 +24,16 @@
17
24
// 4. Return the reversed number.
18
25
// 5. Be sure to print the result returned by the function to verify that your code works for both strings and numbers. Do this before moving on to the next exercise.
// 1. Have a clear, descriptive name like funPhrase.
36
63
// 2. Retrieve only the last character from strings with lengths of 3 or less.
37
64
// 3. Retrieve only the first 3 characters from strings with lengths larger than 3.
38
65
// 4. Use a template literal to return the phrase We put the '___' in '___'. Fill the first blank with the modified string, and fill the second blank with the original string.
39
66
67
+
functionfunPhrase(input){
68
+
letmodifiedInput;
69
+
if(input.length<=3){
70
+
modifiedInput=input.slice(-1)
71
+
returnconsole.log(`We put the ${modifiedInput} in ${input}.`)
72
+
}elsemodifiedInput=input.slice(0,3)
73
+
returnconsole.log(`We put the ${modifiedInput} in ${input}.`)
74
+
}
75
+
funPhrase("Big Phrase");
76
+
40
77
// Test Function
41
78
42
79
// 1. Outside of the function, define the variable str and initialize it with a string (e.g. 'Functions rock!').
43
80
// 2. Call your function and print the returned phrase.
44
81
82
+
letstr="Functions rock!";
83
+
84
+
funPhrase("Functions rock!");
85
+
45
86
// Area of rectangle equal to length x width
46
87
47
88
// 1. Define a function with the required parameters to calculate the area of a rectangle.
48
89
// 2. The function should return the area, NOT print it.
49
90
// 3. Call your area function by passing in two arguments - the length and width.
50
91
// 4. If only one argument is passed to the function, then the shape is a square. Modify your code to deal with this case.
51
92
// 5. Use a template literal to print, “The area is ____ cm^2.”
0 commit comments