Skip to content

Commit 8a11108

Browse files
committed
Functions Studio
2 parents e3b891c + 29c570d commit 8a11108

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

arrays/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let num = "234.54"
2+
num.splice(".")
3+
console.log(num.length)

functions/exercise.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function makeSpaceLine(numSpaces, numChars) {
2+
let spaceLine = ''
3+
for (let i = 0; i < numSpaces; i++) {
4+
spaceLine += '#'
5+
}
6+
return spaceLine
7+
}
8+
9+
function makeIsocelesTriangle(height) {
10+
let triangle = ''
11+
for (let i = 0; i < height; i++) {
12+
triangle += (makeSpaceLine(height - i + 1, 2*i + 1) + "\n")
13+
}
14+
return triangle.slice(0,-1)
15+
}
16+
17+
18+
19+
console.log(makeIsocelesTriangle(5))
20+

loops/studio/solution.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let desserts = ['apple', 'banana', 'more kale', 'ice cream', 'chocolate', 'kiwi'
1212
function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) {
1313
let pantry = [protein, grains, veggies, beverages, desserts];
1414
let meals = [];
15-
15+
1616
/// Part A #2: Write a ``for`` loop inside this function
1717
/// Code your solution for part A #2 below this comment (and above the return statement) ... ///
1818
for (i = 0; i < numMeals; i++) {
@@ -28,9 +28,15 @@ function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) {
2828

2929
function askForNumber() {
3030
let numPass = false
31+
<<<<<<< HEAD
3132

3233
/// CODE YOUR SOLUTION TO PART B here ///
3334

35+
=======
36+
37+
/// CODE YOUR SOLUTION TO PART B here ///
38+
39+
>>>>>>> 29c570d60b0687daa5a55cc58af50bc5ba52461d
3440
while(!numPass) {
3541
numMeals = input.question("How many meals would you like to make?");
3642
if (numMeals > 6 || numMeals < 1 || isNan (numMeals)) {
@@ -54,20 +60,31 @@ function generatePassword(string1, string2) {
5460
}
5561

5662
function runProgram() {
57-
63+
5864
/// TEST PART A #2 HERE ///
5965
/// UNCOMMENT the two lines of code below that invoke the mealAssembly function (starting with 'let meals =') and print the result ///
6066
/// Change the final input variable (aka numMeals) here to ensure your solution makes the right number of meals ///
6167
/// We've started with the number 2 for now. Does your solution still work if you change this value? ///
68+
<<<<<<< HEAD
6269

6370
let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2);
6471
console.log(meals)
6572

73+
=======
74+
75+
let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2);
76+
console.log(meals)
77+
78+
>>>>>>> 29c570d60b0687daa5a55cc58af50bc5ba52461d
6679
}
6780
/// TEST PART B HERE ///
6881
/// UNCOMMENT the next two lines to test your ``askForNumber`` solution ///
6982
/// Tip - don't test this part until you're happy with your solution to part A #2 ///
83+
<<<<<<< HEAD
7084

85+
=======
86+
87+
>>>>>>> 29c570d60b0687daa5a55cc58af50bc5ba52461d
7188
let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
7289
console.log(mealsForX);
7390

0 commit comments

Comments
 (0)