diff --git a/arrays/studio/array-string-conversion/array-testing.js b/arrays/studio/array-string-conversion/array-testing.js index c4d5899385..6eab68c2a1 100644 --- a/arrays/studio/array-string-conversion/array-testing.js +++ b/arrays/studio/array-string-conversion/array-testing.js @@ -8,19 +8,29 @@ strings = [protoArray1, protoArray2, protoArray3, protoArray4]; //2) function reverseCommas() { //TODO: 1. create and instantiate your variables. - let check; - let output; + let check = strings [0]; + let output = []; //TODO: 2. write the code required for this step +if (check.incldes(',')){ + output = check.split(',').reverse().join(',') +} //NOTE: For the code to run properly, you must return your output. this needs to be the final line of code within the function's { }. return output; } + + + //3) function semiDash() { - let check; - let output; + let check = strings[1]; + let output = []; //TODO: write the code required for this step +if (check.includes(';')) { + output = check.split(";").sort().join('-'); +} +console.log(output) return output; @@ -28,19 +38,25 @@ function semiDash() { //4) function reverseSpaces() { - let check; - let output; + let check = strings [2]; + let output = []; //TODO: write the code required for this step - +if (check.includes(' ')){ + output = (check.split(' ').sort().reverse().join(' ')); +} +console.log(output) return output; } //5) function commaSpace() { - let check; - let output; + let check = strings[3]; + let output = []; //TODO: write the code required for this step - + if(check.includes(', ')){ + output = check.split(', ').reverse().join(', '); + } + console.log(output) return output; } diff --git a/arrays/studio/string-modification.js b/arrays/studio/string-modification.js index 45991b15fc..046ab9b876 100644 --- a/arrays/studio/string-modification.js +++ b/arrays/studio/string-modification.js @@ -7,5 +7,11 @@ let str = "LaunchCode"; //Use a template literal to print the original and modified string in a descriptive phrase. //2) Modify your code to accept user input. Query the user to enter the number of letters that will be relocated. +let numLetters = Number(input.question("How many letters will be location?")); +let newString = str.slice(numLetters) + String.SLICE(0, numLetters); //3) Add validation to your code to deal with user inputs that are longer than the word. In such cases, default to moving 3 characters. Also, the template literal should note the error. +if (numletter > 9){ + console.log ("imput exceed length of the word.") + let defaultString = str.slice(3)= str.slice(0, 3); +} \ No newline at end of file diff --git a/booleans-and-conditionals/studio/data-variables-conditionals.js b/booleans-and-conditionals/studio/data-variables-conditionals.js index 6a15e146f4..0266211f6a 100644 --- a/booleans-and-conditionals/studio/data-variables-conditionals.js +++ b/booleans-and-conditionals/studio/data-variables-conditionals.js @@ -1,15 +1,72 @@ // Initialize Variables below -// add logic below to verify total number of astronauts for shuttle launch does not exceed 7 -// add logic below to verify all astronauts are ready -// add logic below to verify the total mass does not exceed the maximum limit of 850000 +let date = "Monday 2019-03-18"; +let time = "10:05:34 AM"; +let astronautCount = 7; +let astronautStatus = "ready"; +let averageAstronautMassKg = 80.7; +let crewMassKg = (astronautCount * averageAstronautMassKg); +let fuelMassKg = 760000; +let shuttleMassKg = 74842.31; +let totalMassKg = crewMassKg + fuelMassKg + shuttleMassKg; +let maximumMassLimit = 850000; +let fuelTempCelsius = -225; +let minimumFuelTemp = -300; +let maximumFuelTemp = -150; +let fuelLevel = "100%"; +let weatherStatus = "clear"; +let preparedForLiftOff = true; +// add logic below to verify total number of astronauts for shuttle launch does not exceed 7 +if (astronautCount > 7) { + preparedForLiftOff = false; + console.log("Security alert! Kick " + (astronautCount - 7) + " astronauts off to launch!"); +} +// add logic below to verify all astronauts are ready +if (astronautStatus !== "ready") { + preparedForLiftOff = false; + console.log("Somehow, one or more astronaut is not ready????"); +} +// add logic below to verify the total mass does not exceed the maximum limit of 850000 +if (totalMassKg > maximumMassLimit) { + console.log("Mass exceeds maximum mass limit!"); + preparedForLiftOff = false; +} // add logic below to verify the fuel temperature is within the appropriate range of -150 and -300 - +if (fuelTempCelsius < minimumFuelTemp || fuelTempCelsius > maximumFuelTemp) { + console.log("Fuel temperature is not in range - DO NOT LAUNCH!"); + preparedForLiftOff = false; +} // add logic below to verify the fuel level is at 100% - +if (fuelLevel !== "100%") { + preparedForLiftOff = false; + console.log("Please refuel before launch."); +} // add logic below to verify the weather status is clear - +if (weatherStatus !== "clear") { + console.log("Weather is not clear."); + preparedForLiftOff = false; +} // Verify shuttle launch can proceed based on above conditions +if (!preparedForLiftOff) { + console.log("ABORT MISSION!"); +} else { + console.log(` + All systems are a go! Initiating space shuttle launch sequence. + --------------------------------------------------------------- + Date: ${date} + Time: ${time} + Astronaut Count: ${astronautCount} + Crew Mass: ${crewMassKg} kg + Fuel Mass: ${fuelMassKg} kg + Shuttle Mass: ${shuttleMassKg} kg + Total Mass: ${totalMassKg} kg + Fuel Temperature: ${fuelTempCelsius} C + Weather Status: ${weatherStatus} + --------------------------------------------------------------- + Have a safe trip astronauts!`); +} + + diff --git a/data-and-variables/exercises/data-and-variables-exercises.js b/data-and-variables/exercises/data-and-variables-exercises.js index 6433bcd641..b27c040e92 100644 --- a/data-and-variables/exercises/data-and-variables-exercises.js +++ b/data-and-variables/exercises/data-and-variables-exercises.js @@ -1,9 +1,19 @@ // Declare and assign the variables below - +let shuttlename = 'determination'; +let shuttlespeedMph = 175000; +let distanceTomarsKm = 225000000; +let distanceTomoonKm = 384400; +const milesPerkm = 0.621; // Use console.log to print the 'typeof' each variable. Print one item per line. - +console.log (typeof (shuttlename)); +console.log (typeof ("shuttlespeedMph")); +console.log (typeof (distanceTomarsKm)); +console.log (typeof (distanceTomoonKm)); +console.log (typeof ( milesPerkm)); // Calculate a space mission below - +let milesToMars = kilometersToMars * milesPerKilometer; +let hoursToMars = milesToMars / shuttlespeedMph; +let daysToMars = hoursToMars / 24; // Print the results of the space mission calculations below // Calculate a trip to the moon below diff --git a/errors-and-debugging/exercises/Debugging1stSyntaxError.js b/errors-and-debugging/exercises/Debugging1stSyntaxError.js index 365af5a964..f35a8c49d2 100644 --- a/errors-and-debugging/exercises/Debugging1stSyntaxError.js +++ b/errors-and-debugging/exercises/Debugging1stSyntaxError.js @@ -4,7 +4,7 @@ let launchReady = false; let fuelLevel = 17000; -if (fuelLevel >= 20000 { +if (fuelLevel >= 20000) { console.log('Fuel level cleared.'); launchReady = true; } else { diff --git a/errors-and-debugging/exercises/DebuggingLogicErrors2.js b/errors-and-debugging/exercises/DebuggingLogicErrors2.js index 160a0c2cd0..354f2e69ba 100644 --- a/errors-and-debugging/exercises/DebuggingLogicErrors2.js +++ b/errors-and-debugging/exercises/DebuggingLogicErrors2.js @@ -14,7 +14,7 @@ if (fuelLevel >= 20000) { launchReady = true; } else { console.log('WARNING: Insufficient fuel!'); - launchReady = false; + launchReady = false; console.log(launchReady) } // if (crewStatus && computerStatus === 'green'){ diff --git a/loops/studio/solution.js b/loops/studio/solution.js index 4e21a9caa5..fd80d76606 100644 --- a/loops/studio/solution.js +++ b/loops/studio/solution.js @@ -2,11 +2,11 @@ const input = require('readline-sync'); // Part A: #1 Populate these arrays -let protein = []; -let grains = []; -let veggies = []; -let beverages = []; -let desserts = []; +let protein = ['chicken', 'pork', 'tofu', 'beef', 'fish', 'beans']; +let grains = ['rice', 'pasta', 'corn', 'potato', 'quinoa', 'crackers']; +let veggies = ['peas', 'green beans', 'kale', 'edamame', 'broccoli', 'asparagus']; +let beverages = ['juice', 'milk', 'water', 'soy milk', 'soda', 'tea']; +let desserts = ['apple', 'banana', 'more kale', 'ice cream', 'chocolate', 'kiwi']; function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) { @@ -15,7 +15,14 @@ function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) { /// Part A #2: Write a ``for`` loop inside this function /// Code your solution for part A #2 below this comment (and above the return statement) ... /// - + for (let i = 0; i < numMeals; i++) { + let meal = []; + + for (let j = 0; j < pantry.length; j++) { + meal.push(pantry[j][i]) + } + meals.push(meal) + } return meals; } @@ -25,6 +32,9 @@ function askForNumber() { numMeals = input.question("How many meals would you like to make?"); /// CODE YOUR SOLUTION TO PART B here /// + while (numMeals < 1 || numMeals > 6 || isNaN(numMeals)) { + numMeals = input.question("I can only make 1-6 meals. How many would you like? "); + } return numMeals; } @@ -34,6 +44,10 @@ function generatePassword(string1, string2) { let code = ''; /// Code your Bonus Mission Solution here /// +for (let i = 0; 1 < string1.length; i++) { + code+= string1[i] + string2[i]; +} + return code; } @@ -45,8 +59,8 @@ function runProgram() { /// Change the final input variable (aka numMeals) here to ensure your solution makes the right number of meals /// /// We've started with the number 2 for now. Does your solution still work if you change this value? /// - // let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2); - // console.log(meals) + let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2); + console.log(meals) /// TEST PART B HERE /// @@ -59,10 +73,10 @@ function runProgram() { /// TEST PART C HERE /// /// UNCOMMENT the remaining commented lines and change the password1 and password2 strings to ensure your code is doing its job /// - // let password1 = ''; - // let password2 = ''; - // console.log("Time to run the password generator so we can update the menu tomorrow.") - // console.log(`The new password is: ${generatePassword(password1, password2)}`); + let password1 = 'LoOt'; + let password2 = 'oku!'; + console.log("Time to run the password generator so we can update the menu tomorrow.") + console.log(`The new password is: ${generatePassword(password1, password2)}`); } module.exports = { diff --git a/more-on-functions/studio/part-one-find-minimum-value.js b/more-on-functions/studio/part-one-find-minimum-value.js index 4fa8c129d0..14c7e64bca 100644 --- a/more-on-functions/studio/part-one-find-minimum-value.js +++ b/more-on-functions/studio/part-one-find-minimum-value.js @@ -1,5 +1,17 @@ //1) Create a function with an array of numbers as its parameter. The function should iterate through the array and return the minimum value from the array. Hint: Use what you know about if statements to identify and store the smallest value within the array. +function findMiniValue(arr) { + let minimum = arr[0]; + for (let i = 0; i < arr.length; i++) { + if (arr[i] < minimum) { + minimum = arr[i]; + } +} + + + + return minimum; +} //Sample arrays for testing: let nums1 = [5, 10, 2, 42]; let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3]; @@ -7,4 +19,7 @@ let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0]; //Using one of the test arrays as the argument, call your function inside the console.log statement below. -console.log(/* your code here */); +console.log(findMiniValue(nums1)); +console.log(findMiniValue(nums2)); +console.log(findMiniValue(nums3)); + diff --git a/more-on-functions/studio/part-three-number-sorting-easy-way.js b/more-on-functions/studio/part-three-number-sorting-easy-way.js index bfa9748a32..6ee057f6b7 100644 --- a/more-on-functions/studio/part-three-number-sorting-easy-way.js +++ b/more-on-functions/studio/part-three-number-sorting-easy-way.js @@ -4,5 +4,10 @@ let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3]; let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0]; //Sort each array in ascending order. - +console.log(nums1.sort((a, b) => a - b)); +console.log(nums2.sort((a, b) => a - b)); +console.log(nums3.sort((a, b) => a - b)); //Sort each array in descending order. +console.log(nums1.sort((a, b) => b - a)); +console.log(nums2.sort((a, b) => a - b)); +console.log(nums3.sort((a, b) => a - b)); \ No newline at end of file diff --git a/more-on-functions/studio/part-two-create-sorted-array.js b/more-on-functions/studio/part-two-create-sorted-array.js index bc362a3101..16fcd476c5 100644 --- a/more-on-functions/studio/part-two-create-sorted-array.js +++ b/more-on-functions/studio/part-two-create-sorted-array.js @@ -19,11 +19,43 @@ function findMinValue(arr){ 6) Be sure to print the results in order to verify your code.*/ //Your function here... +function sortArray(unsortedArray){ + let newArray =[]; + while(unsortedArray.length !== 0) { + let smallestValue = findMinValue(unsortedArray); + newArray.push(smallestValue); + unsortedArray.splice(unsortedArray.indexOf(smallestValue),1); + + } + return newArray; +} /* BONUS MISSION: Refactor your sorting function to use recursion below: */ +function recursiveSortArray(unsortedArray, newArray = []) { + if(unsortedArray.length === 1) { + newArray.push(unsortedArray[0]); + } else { + newArray.push(findMinValue(unsortedArray)); + unsortedArray.splice(unsortedArray.indexOf(findMinValue(unsortedArray)), 1); + recursiveSortArray(unsortedArray,newArray); + } + + + + return newArray; +} + + + + + //Sample arrays for testing: let nums1 = [5, 10, 2, 42]; let nums2 = [-2, 0, -10, -44, 5, 3, 0, 3]; let nums3 = [200, 5, 4, 10, 8, 5, -3.3, 4.4, 0]; + +console.log(recursiveSortArray(nums1)); +console.log(recursiveSortArray(nums2)); +console.log(recursiveSortArray(nums3)); diff --git a/objects-and-math/exercises/ObjectExercises.js b/objects-and-math/exercises/ObjectExercises.js index 9a50cbdecc..d88e3e3aa1 100644 --- a/objects-and-math/exercises/ObjectExercises.js +++ b/objects-and-math/exercises/ObjectExercises.js @@ -12,6 +12,36 @@ let salamander = { age: 5 }; +let superChimpTwo = { + name: "Brad", + species: "Chimpanzee", + mass: 11, + age: 6, + astronautID: 3, + move: function () {return Math.floor(Math.random()*11)} +}; + +let dog = { + name: "Leroy", + species: "Beagle", + mass: 14, + age: 5, + astronautID: 4, + move: function () {return Math.floor(Math.random()*11)} +}; + +let waterBear = { + name: "Almina", + species: "Tardigrade", + mass: 0.0000000001, + age: 1, + astronautID: 5, +}; + +let crew = [superChimpOne, superChimpTwo, salamander, dog, waterBear]; + + +let crew = [superChimpOne, superChimpTwo, salamander, dog, waterBear]; // After you have created the other object literals, add the astronautID property to each one.