Skip to content

Commit 745513a

Browse files
committed
Functions Studio
2 parents 082e655 + 203c578 commit 745513a

File tree

2 files changed

+102
-16
lines changed

2 files changed

+102
-16
lines changed
Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,69 @@
11
// Initialize Variables below
2+
let date = "Monday 2019-03-18"
3+
let time = "10:05:34 AM"
4+
let astronautCount = 7
5+
let astronautStatus = "ready"
6+
let averageAstronautMassKg = 80.7
7+
let crewMassKg = astronautCount * averageAstronautMassKg
8+
let fuelMassKg = 760000
9+
let shuttleMassKg = 74842.31
10+
let totalMassKg = crewMassKg + fuelMassKg + shuttleMassKg
11+
let maximumMassLimit = 850000
12+
let fuelTemplCelsius = -225
13+
let minimumFuelTemp = -300
14+
let maximumFuelTemp = -150
15+
let fuelLevel = "100%"
16+
let weatherStatus = "clear"
17+
let preparedForLiftOff = false
18+
let divider = "------------------------------------------"
219

20+
console.log("Assessing pre-liftoff requirements...\n", divider +"\n", date +"\n",time)
321
// add logic below to verify total number of astronauts for shuttle launch does not exceed 7
4-
22+
if (astronautCount > 7) {
23+
console.log("Too many astronauts!");
24+
preparedForLiftOff = false;
25+
} else {
26+
console.log("There are a normal amount of astronauts.");
27+
}
528
// add logic below to verify all astronauts are ready
6-
29+
if (astronautStatus != "ready") {
30+
console.log("The astronauts refused!");
31+
preparedForLiftOff = false;
32+
} else {
33+
console.log("The astronauts are good to go.")
34+
}
735
// add logic below to verify the total mass does not exceed the maximum limit of 850000
8-
36+
if (totalMassKg > maximumMassLimit) {
37+
console.log("Total mass EXCEEDED")
38+
preparedForLiftOff = false;
39+
} else {
40+
console.log("Total mass NOT exceeded")
41+
}
942
// add logic below to verify the fuel temperature is within the appropriate range of -150 and -300
10-
43+
if (fuelTemplCelsius < -300 || fuelTemplCelsius > -150) {
44+
console.log("Fuel temperature irregular.")
45+
preparedForLiftOff = false;
46+
} else {
47+
console.log("Fuel temperature normal!")
48+
}
1149
// add logic below to verify the fuel level is at 100%
12-
50+
if (fuelLevel === "100%") {
51+
console.log("Fuel level 100%.")
52+
} else {
53+
console.log("Fueling required!")
54+
preparedForLiftOff = false;
55+
}
1356
// add logic below to verify the weather status is clear
14-
57+
if (weatherStatus === "clear") {
58+
console.log("Weather is clear.")
59+
} else {
60+
console.log("Weather does not meet standard.")
61+
preparedForLiftOff = false;
62+
}
63+
console.log(divider)
1564
// Verify shuttle launch can proceed based on above conditions
65+
if (preparedForLiftOff == false) {
66+
console.log("Cannot liftoff at this time. Hold out astronauts!")
67+
} else {
68+
console.log("Prepare for liftoff. Have fun astronauts!")
69+
}

functions/studio/studio-functions.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
1-
//We want to COMPLETELY reverse an array by flipping the order of the entries AND flipping the order of characters in each element.
1+
//We want to COMPLETELY reverse an stray by flipping the order of the entries AND flipping the order of characters in each element.
2+
3+
function reverseCharacters(str) {
4+
if (typeof str === "number") {
5+
return Number(String(str).split("").reverse().join(""))
6+
}
7+
return str.split("").reverse().join("")
8+
9+
10+
}
11+
12+
let myVariableName = 1234567
13+
14+
console.log(reverseCharacters(myVariableName))
15+
216

317
// Part One: Reverse Characters
418

519
// 1. Define the function as reverseCharacters. Give it one parameter, which will be the string to reverse.
6-
// 2. Within the function, split the string into an array, then reverse the array.
20+
// 2. Within the function, split the string into an stray, then reverse the stray.
21+
722
// 3. Use join to create the reversed string and return that string from the function.
23+
24+
825
// 4. Below the function, define and initialize a variable to hold a string.
26+
27+
928
// 5. Use console.log(reverseCharacters(myVariableName)); to call the function and verify that it correctly reverses the characters in the string.
29+
30+
1031
// 6. Optional: Use method chaining to reduce the lines of code within the function.
1132

1233
// Part Two: Reverse Digits
@@ -19,17 +40,25 @@
1940

2041
// Part Three: Complete Reversal
2142

22-
// 1. Define and initialize an empty array.
23-
// 2. Loop through the old array.
24-
// 3. For each element in the old array, call reverseCharacters to flip the characters or digits.
25-
// 4. Add the reversed string (or number) to the array defined in part ‘a’.
26-
// 5. Return the final, reversed array.
43+
// 1. Define and initialize an empty stray.
44+
// 2. Loop through the old stray.
45+
// 3. For each element in the old stray, call reverseCharacters to flip the characters or digits.
46+
// 4. Add the reversed string (or number) to the stray defined in part ‘a’.
47+
// 5. Return the final, reversed stray.
2748
// 6. Be sure to print the results from each test case in order to verify your code.
2849

29-
let arrayTest1 = ['apple', 'potato', 'Capitalized Words'];
30-
let arrayTest2 = [123, 8897, 42, 1168, 8675309];
31-
let arrayTest3 = ['hello', 'world', 123, 'orange'];
50+
let strayTest1 = ['apple', 'potato', 'Capitalized Words'];
51+
let strayTest2 = [123, 8897, 42, 1168, 8675309];
52+
let strayTest3 = ['hello', 'world', 123, 'orange'];
3253

54+
function completeReversal(oldArr) {
55+
let arr = []
56+
for (i = 0; i < oldArr.length; i++) {
57+
arr.unshift(reverseCharacters(oldArr[i]))
58+
}
59+
return arr
60+
}
61+
console.log(completeReversal(strayTest1))
3362
// Bonus Missions
3463

3564
// 1. Have a clear, descriptive name like funPhrase.
@@ -49,3 +78,6 @@ let arrayTest3 = ['hello', 'world', 123, 'orange'];
4978
// 3. Call your area function by passing in two arguments - the length and width.
5079
// 4. If only one argument is passed to the function, then the shape is a square. Modify your code to deal with this case.
5180
// 5. Use a template literal to print, “The area is ____ cm^2.”
81+
82+
function areaOfRectangle()
83+

0 commit comments

Comments
 (0)