diff --git a/arrays/exercises/part-five-arrays.js b/arrays/exercises/part-five-arrays.js index 4cdf1bba41..09b91ddf7c 100644 --- a/arrays/exercises/part-five-arrays.js +++ b/arrays/exercises/part-five-arrays.js @@ -3,9 +3,19 @@ let arr = ['B', 'n', 'n', 5]; //1) Use the split method on the string to identify the purpose of the parameter inside the (). +console.log(str.split("")); // splits the string by individual characters into an array. +console.log(str.split(" ")); // splits the string and separates by one space into an array. + //2) Use the join method on the array to identify the purpose of the parameter inside the (). +console.log(arr.join("")); // joins together the elements of an array into a string with nothing inbetween. +console.log(arr.join(" ")); // joins together the elements of an array into a string with what is inside the parameter. + //3) Do split or join change the original string/array? +// NO. Split and join do not change the original string/array. + //4) We can take a comma-separated string and convert it into a modifiable array. Try it! Alphabetize the cargoHold string, and then combine the contents into a new string. let cargoHold = "water,space suits,food,plasma sword,batteries"; + +console.log(cargoHold.split(",").sort().join(",")); \ No newline at end of file diff --git a/arrays/exercises/part-four-arrays.js b/arrays/exercises/part-four-arrays.js index 498149702e..b1396582c6 100644 --- a/arrays/exercises/part-four-arrays.js +++ b/arrays/exercises/part-four-arrays.js @@ -5,6 +5,31 @@ let holdCabinet2 = ['orange drink', 'nerf toys', 'camera', 42, 'parsnip']; //1) Print the result of using concat on the two arrays. Does concat alter the original arrays? Verify this by printing holdCabinet1 after using the method. +let holdCabinet = holdCabinet1.concat(holdCabinet2); +console.log(holdCabinet); +console.log(holdCabinet1); + +// .concat() does not alter the original arrays. + //2) Print a slice of two elements from each array. Does slice alter the original arrays? +holdCabinet1.slice(1, 2); +console.log(holdCabinet1); +console.log(holdCabinet1.slice(1, 2)); + +holdCabinet2.slice(0, 2); +console.log(holdCabinet2); +console.log(holdCabinet2.slice(0, 2)); + +// .slice() does not alter the original arrays. + //3) reverse the first array, and sort the second. What is the difference between these two methods? Do the methods alter the original arrays? + +holdCabinet1.reverse(); +console.log(holdCabinet1); + +holdCabinet2.sort(); +console.log(holdCabinet2); + +// .reverse() reverses the array and .sort() sorts the array (number accending, then alphabetical) +// the methods do change the arrays \ No newline at end of file diff --git a/arrays/exercises/part-one-arrays.js b/arrays/exercises/part-one-arrays.js index 92f4e45170..143b92806b 100644 --- a/arrays/exercises/part-one-arrays.js +++ b/arrays/exercises/part-one-arrays.js @@ -1,5 +1,17 @@ //Create an array called practiceFile with the following entry: 273.15 +let practiceFile = [273.15]; +console.log(practiceFile); + //Use the bracket notation method to add "42" and "hello" to the array. Add these new items one at a time. Print the array after each step to confirm the changes. +practiceFile[1] = 42; +console.log(practiceFile); + +practiceFile[2] = "hello"; +console.log(practiceFile); + //Use a single .push() to add the following items: false, -4.6, and "87". Print the array to confirm the changes. + +practiceFile.push(false, -4.6, "87"); +console.log(practiceFile); \ No newline at end of file diff --git a/arrays/exercises/part-six-arrays.js b/arrays/exercises/part-six-arrays.js index d0a28bed56..63f6a66d22 100644 --- a/arrays/exercises/part-six-arrays.js +++ b/arrays/exercises/part-six-arrays.js @@ -2,10 +2,64 @@ //1) Define and initialize the arrays specified in the exercise to hold the name, chemical symbol and mass for different elements. +let element1 = ['hydrogen', 'H', 1.008]; +let element2 = ['helium', 'He', 4.003]; +let element26 = ['iron', 'Fe', 55.85]; + //2) Define the array 'table', and use 'push' to add each of the element arrays to it. Print 'table' to see its structure. +let table = []; + +table.push(element1, element2, element26); + +console.log(table); + //3) Use bracket notation to examine the difference between printing 'table' with one index vs. two indices (table[][]). +console.log(table[0]); +console.log(table[1]); +console.log(table[2]); + +console.log(table[0][0]); +console.log(table[0][1]); +console.log(table[0][2]); + +console.log(table[1][0]); +console.log(table[1][1]); +console.log(table[1][2]); + +console.log(table[2][0]); +console.log(table[2][1]); +console.log(table[2][2]); + //4) Using bracket notation and the table array, print the mass of element1, the name for element 2 and the symbol for element26. +console.log(`Mass of element1: ${table[0][2]}`); + +console.log(`Name of element2: ${table[1][0]}`); + +console.log(`Symbol of element26: ${table[2][1]}`); + //5) 'table' is an example of a 2-dimensional array. The first “level” contains the element arrays, and the second level holds the name/symbol/mass values. Experiment! Create a 3-dimensional array and print out one entry from each level in the array. + +let threeD = [ + [ + [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] + ] +] + +console.log(threeD[1]); +console.log(threeD[0][1]); +console.log(threeD[2][0][1]); \ No newline at end of file diff --git a/arrays/exercises/part-three-arrays.js b/arrays/exercises/part-three-arrays.js index d43918a702..40339680f6 100644 --- a/arrays/exercises/part-three-arrays.js +++ b/arrays/exercises/part-three-arrays.js @@ -4,6 +4,15 @@ let cargoHold = [1138, 'space suits', 'parrot', 'instruction manual', 'meal pack //1) Insert the string 'keys' at index 3 without replacing any other entries. +cargoHold.splice(3, 0, 'keys'); +console.log(cargoHold); + //2) Remove ‘instruction manual’ from the array. (Hint: indexOf is helpful to avoid manually counting an index). +cargoHold.splice(cargoHold.indexOf('instruction manual'), 1); +console.log(cargoHold); + //3) Replace the elements at indexes 2 - 4 with the items ‘cat’, ‘fob’, and ‘string cheese’. + +cargoHold.splice(2, 3, 'cat', 'fob', 'string cheese'); +console.log(cargoHold); \ No newline at end of file diff --git a/arrays/exercises/part-two-arrays.js b/arrays/exercises/part-two-arrays.js index a940b1d0ff..dd88a05815 100644 --- a/arrays/exercises/part-two-arrays.js +++ b/arrays/exercises/part-two-arrays.js @@ -2,10 +2,29 @@ let cargoHold = ['oxygen tanks', 'space suits', 'parrot', 'instruction manual', //1) Use bracket notation to replace ‘slinky’ with ‘space tether’. Print the array to confirm the change. +cargoHold[5] = 'space tether'; +console.log(cargoHold); + //2) Remove the last item from the array with pop. Print the element removed and the updated array. +let lastItem = cargoHold.pop(); +console.log(lastItem); +console.log(cargoHold); + //3) Remove the first item from the array with shift. Print the element removed and the updated array. +let firstItem = cargoHold.shift(); +console.log(firstItem); +console.log(cargoHold); + //4) Unlike pop and shift, push and unshift require arguments inside the (). Add the items 1138 and ‘20 meters’ to the the array - the number at the start and the string at the end. Print the updated array to confirm the changes. +cargoHold.unshift(1138); +cargoHold.push('20 meters'); +console.log(cargoHold); + //5) Use a template literal to print the final array and its length. + +console.log( +`Array: ${cargoHold} +Length: ${cargoHold.length}.`); \ No newline at end of file diff --git a/arrays/studio/array-string-conversion/array-testing.js b/arrays/studio/array-string-conversion/array-testing.js index c4d5899385..ea8081e780 100644 --- a/arrays/studio/array-string-conversion/array-testing.js +++ b/arrays/studio/array-string-conversion/array-testing.js @@ -8,9 +8,14 @@ strings = [protoArray1, protoArray2, protoArray3, protoArray4]; //2) function reverseCommas() { //TODO: 1. create and instantiate your variables. - let check; + let check = protoArray1.includes(","); + + let output; //TODO: 2. write the code required for this step + if (check) { + output = protoArray1.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; @@ -18,29 +23,37 @@ function reverseCommas() { //3) function semiDash() { - let check; + let check = protoArray2.includes(";"); let output; //TODO: write the code required for this step - + if (check) { + output = protoArray2.split(";").sort().join("-"); + } return output; } //4) function reverseSpaces() { - let check; + let check = protoArray3.includes(" "); let output; //TODO: write the code required for this step + if (check) { + output = protoArray3.split(" ").sort().reverse().join(" "); + } return output; } //5) function commaSpace() { - let check; + let check = protoArray4.includes(", "); let output; //TODO: write the code required for this step - + if (check) { + output = protoArray4.split(", ").reverse().join(","); + } + return output; } diff --git a/arrays/studio/multi-dimensional-arrays.js b/arrays/studio/multi-dimensional-arrays.js index 18761a8934..ca3169813d 100644 --- a/arrays/studio/multi-dimensional-arrays.js +++ b/arrays/studio/multi-dimensional-arrays.js @@ -1,3 +1,5 @@ +const input = require('readline-sync'); + let food = "water bottles,meal packs,snacks,chocolate"; let equipment = "space suits,jet packs,tool belts,thermal detonators"; let pets = "parrots,cats,moose,alien eggs"; @@ -5,10 +7,48 @@ let sleepAids = "blankets,pillows,eyepatches,alarm clocks"; //1) Use split to convert the strings into four cabinet arrays. Alphabetize the contents of each cabinet. +let foodArr = food.split(",").sort(); +console.log(foodArr); + +let equipmentArr = equipment.split(",").sort(); +console.log(equipmentArr); + +let petsArr = pets.split(",").sort(); +console.log(petsArr); + +let sleepAidsArr = sleepAids.split(",").sort(); +console.log(sleepAidsArr); + //2) Initialize a cargoHold array and add the cabinet arrays to it. Print cargoHold to verify its structure. +let cargoHold = []; + +cargoHold.push(foodArr, equipmentArr, petsArr, sleepAidsArr); +console.log(cargoHold); + //3) Query the user to select a cabinet (0 - 3) in the cargoHold. +let selectCabinet = input.question("Choose a number (0, 1, 2, or 3): "); + //4) Use bracket notation and a template literal to display the contents of the selected cabinet. If the user entered an invalid number, print an error message. +if (selectCabinet >= 0 && selectCabinet <= 3) { + console.log(`The contents of the selected canbinet: ${cargoHold[selectCabinet]}`); +} else { + console.error(`The number ${selectCabinet} is out of range.`); +} + //5) Modify the code to query the user for BOTH a cabinet in cargoHold AND a particular item. Use the 'includes' method to check if the cabinet contains the selected item, then print “Cabinet ____ DOES/DOES NOT contain ____.” + +let num = input.question("Choose a number (0, 1, 2, or 3): "); +let item = input.question("What item are you looking for?: "); + +if (num >= 0 && num <= 3) { + if (cargoHold[num].includes(item.trim().toLowerCase())) { + console.log(`Cabinet ${num} DOES contain ${item}.`); + } else { + console.log(`Cabinet ${num} DOES NOT contain ${item}.`); + } +} else { + console.error(`The number ${num} is out of range.`); +} \ No newline at end of file diff --git a/arrays/studio/string-modification.js b/arrays/studio/string-modification.js index 45991b15fc..1deeda55c3 100644 --- a/arrays/studio/string-modification.js +++ b/arrays/studio/string-modification.js @@ -4,8 +4,30 @@ let str = "LaunchCode"; //1) Use string methods to remove the first three characters from the string and add them to the end. //Hint - define another variable to hold the new string or reassign the new string to str. +let firstThree = str.slice(0, 3); +let last = str.slice(3) +console.log(last.concat(firstThree)); + //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 num = input.question("Enter a number: "); +let part1 = ''; +let part2 = ''; +let combined = ''; + //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 (num > str.length) { + part1 = str.slice(0, 3); + part2 = str.slice(3); + combined = part2.concat(part1); + console.log(`Number entered, ${num}, is greater than the length of the string 'LaunchCode', ${str.length}. + Returning default, with num = 3: ${combined}`); +} else { + part1 = str.slice(0, num); + part2 = str.slice(num); + combined = part2.concat(part1); + console.log(`With num = ${num}, the first ${num} letters moved to the end looks like this: ${combined}`); +} \ No newline at end of file diff --git a/booleans-and-conditionals/exercises/part-1.js b/booleans-and-conditionals/exercises/part-1.js index b829140a07..7392b64eb0 100644 --- a/booleans-and-conditionals/exercises/part-1.js +++ b/booleans-and-conditionals/exercises/part-1.js @@ -1,5 +1,12 @@ // Declare and initialize the variables for exercise 1 here: +let engineIndicatorLight = "red blinking"; +let spaceSuitsOn = true; +let shuttleCabinReady = true; +let crewStatus = spaceSuitsOn && shuttleCabinReady; +let computerStatusCode = 200; +let shuttleSpeed = 15000; + // BEFORE running the code, predict what will be printed to the console by the following statements: if (engineIndicatorLight === "green") { diff --git a/booleans-and-conditionals/exercises/part-2.js b/booleans-and-conditionals/exercises/part-2.js index ff11fbab8a..ba519a5ef1 100644 --- a/booleans-and-conditionals/exercises/part-2.js +++ b/booleans-and-conditionals/exercises/part-2.js @@ -9,13 +9,34 @@ let shuttleSpeed = 15000; // a) If crewStatus is true, print "Crew Ready" else print "Crew Not Ready". +if (crewStatus === true) { + console.log("Crew Ready"); +} else { + console.log("Crew Not Ready"); +} // b) If computerStatusCode is 200, print "Please stand by. Computer is rebooting." Else if computerStatusCode is 400, print "Success! Computer online." Else print "ALERT: Computer offline!" +if (computerStatusCode === 200) { + console.log("Please stand by. Computer is rebooting."); +} else if (computerStatusCode === 400) { + console.log("Sucess! Computer online."); +} else { + console.log("ALERT: Computer offline!"); +} // c) If shuttleSpeed is > 17,500, print "ALERT: Escape velocity reached!" Else if shuttleSpeed is < 8000, print "ALERT: Cannot maintain orbit!" Else print "Stable speed". +if (shuttleSpeed > 17500) { + console.log("ALERT: Escape velocity reached!"); +} else if (shuttleSpeed < 8000) { + console.log("ALERT: Cannot maintain orbit!"); +} else { + console.log("Stable speed"); +} // 4) PREDICT: Do the code blocks shown in the 'predict.txt' file produce the same result? -console.log(/* "Yes" or "No" */); +console.log("Yes"); + + diff --git a/booleans-and-conditionals/exercises/part-3.js b/booleans-and-conditionals/exercises/part-3.js index 9ed686d097..65789e5fa4 100644 --- a/booleans-and-conditionals/exercises/part-3.js +++ b/booleans-and-conditionals/exercises/part-3.js @@ -18,7 +18,39 @@ f) Otherwise, print "Fuel and engine status pending..." */ // Code 5a - 5f here: +if (fuelLevel < 1000 || engineTemperature > 3500 || engineIndicatorLight === "red blinking") { + console.log("ENGINE FAILURE IMMINENT!"); +} else if (fuelLevel <= 5000 || engineTemperature > 2500) { + console.log("Check fuel level. Engines running hot."); +} else if (fuelLevel > 20000 && engineTemperature <= 2500) { + console.log("Full tank. Engines good."); +} else if (fuelLevel > 10000 && engineTemperature <= 2500) { + console.log("Fuel level above 50%. Engines good."); +} else if (fuelLevel > 5000 && engineTemperature <= 2500) { + console.log("Fuel level above 25%. Engines good."); +} else { + console.log("Fuel and engine status pending..."); +} + // 6) a) Create the variable commandOverride, and set it to be true or false. If commandOverride is false, then the shuttle should only launch if the fuel and engine check are OK. If commandOverride is true, then the shuttle will launch regardless of the fuel and engine status. +let commandOverride = false; + +if (!commandOverride) { + if (fuelLevel > 20000 && engineTemperature <= 2500) { + console.log("Full tank. Engines good."); + } +} + +if (commandOverride) { + console.log("Override initiated. Prepare to launch."); +} + /* 6) b) Code the following if/else check: If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */ + +if ((fuelLevel > 20000 && engineIndicatorLight !== "red blinking") || commandOverride === true) { + console.log("Cleared to launch!"); +} else { + console.log("Launch scrubbed!"); +} \ 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..2bbdeb231d 100644 --- a/booleans-and-conditionals/studio/data-variables-conditionals.js +++ b/booleans-and-conditionals/studio/data-variables-conditionals.js @@ -1,5 +1,22 @@ // Initialize Variables below +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 // add logic below to verify all astronauts are ready @@ -13,3 +30,22 @@ // add logic below to verify the weather status is clear // Verify shuttle launch can proceed based on above conditions + +if ((astronautCount <= 7) && (astronautStatus === 'ready') && (totalMassKg < maximumMassLimit) && (fuelTempCelsius >= minimumFuelTemp || fuelTempCelsius <= maximumFuelTemp) && (fuelLevel === 100) && (weatherStatus === 'clear')) { + console.log( + "All systems are a go! Initiating space shuttle launch sequence.\n" + + "----------------------------------------------------------------\n" + + "Date: " + date + "\n" + + "Time: " + time + "\n" + + "Astronaught Count: " + astronautCount + "\n" + + "Crew Mass: " + crewMassKg + " kg\n" + + "Fuel Mass: " + fuelMassKg + " kg\n" + + "Shuttle Mass: " + shuttleMassKg + " kg\n" + + "Total Mass: " + totalMassKg + " kg\n" + + "Fuel Temperature: " + fuelTempCelsius + " °C\n" + + "Weather Status: " + weatherStatus + "\n" + + "----------------------------------------------------------------\n" + + "Have a safe trip astronauts!" + ); +} + diff --git a/classes/exercises/ClassExercises.js b/classes/exercises/ClassExercises.js index 91b9ee5b9d..24b787ec20 100644 --- a/classes/exercises/ClassExercises.js +++ b/classes/exercises/ClassExercises.js @@ -1,10 +1,69 @@ // Define your Book class here: +class Book { + constructor(title, author, copyrightDate, iSBN, pages, numCheckout, discarded) { + this.title = title; + this.author = author; + this.copyrightDate = copyrightDate; + this.iSBN = iSBN; + this.pages = pages; + this.numCheckout = numCheckout; + this.discarded = discarded; + } + + checkout(num) { + this.numCheckout += num; + } +} // Define your Manual and Novel classes here: +class Manual extends Book { + constructor(title, author, copyrightDate, iSBN, pages, numCheckout, discarded) { + super(title, author, copyrightDate, iSBN, pages, numCheckout, discarded); + } + + dispose(year) { + if (year - this.copyrightDate > 5) { + this.discarded = 'Yes'; + } + } +} + +class Novel extends Book { + constructor(title, author, copyrightDate, iSBN, pages, numCheckout, discarded) { + super(title, author, copyrightDate, iSBN, pages, numCheckout, discarded); + } + + dispose() { + if (this.numCheckout > 100) { + this.discarded = 'Yes'; + } + } +} // Declare the objects for exercises 2 and 3 here: +let novel1 = new Novel('Pride and Prejudice', 'Jane Austen', 1813, '1111111111111', 432, 32, 'No'); +let manual1 = new Manual('Top Secret Shuttle Building Manual', 'Redacted', 2013, '0000000000000', 1147, 1, 'No'); + +// Code exercises 4 & 5 here: + +console.log(`Has the novel '${novel1.title}' by ${novel1.author} been disposed?: ${novel1.discarded}`); +console.log(`Has the novel '${manual1.title}' by ${novel1.author} been disposed?: ${manual1.discarded}`); + +novel1.dispose(); +manual1.dispose(2024); + +console.log(`Has the novel '${novel1.title}' by ${novel1.author} been disposed?: ${novel1.discarded}`); +console.log(`Has the novel '${manual1.title}' by ${novel1.author} been disposed?: ${manual1.discarded}`); + +console.log(`Number of times '${novel1.title}' by ${novel1.author} has been checked out: ${novel1.numCheckout}`); + +novel1.checkout(5); + +console.log(`Number of times '${novel1.title}' by ${novel1.author} has been checked out: ${novel1.numCheckout}`); + +novel1.dispose(); -// Code exercises 4 & 5 here: \ No newline at end of file +console.log(`Has the novel '${novel1.title}' by ${novel1.author} been disposed?: ${novel1.discarded}`); \ No newline at end of file diff --git a/css/exercises/Git-Exercises.png b/css/exercises/Git-Exercises.png new file mode 100644 index 0000000000..2f43aa342e Binary files /dev/null and b/css/exercises/Git-Exercises.png differ diff --git a/css/exercises/index.html b/css/exercises/index.html index 922e8e3885..fa85869f45 100644 --- a/css/exercises/index.html +++ b/css/exercises/index.html @@ -9,13 +9,13 @@
-Web Development is a very cool skill that I love learning!
I love making websites because all I have to do is reload the page to see the changes I have made!
diff --git a/css/exercises/styles.css b/css/exercises/styles.css index 3b88bed453..635c6046df 100644 --- a/css/exercises/styles.css +++ b/css/exercises/styles.css @@ -1 +1,25 @@ /* Start adding your styling below! */ + +body { + background-color: yellow; +} + +p { + color: green; +} + +h1 { + font-size: 36px; +} + +.center { + text-align: center; +} + +#cool-text { + color: blue; +} + +#pink-text { + color: pink; +} \ No newline at end of file diff --git a/data-and-variables/exercises/data-and-variables-exercises.js b/data-and-variables/exercises/data-and-variables-exercises.js index 6433bcd641..696148752a 100644 --- a/data-and-variables/exercises/data-and-variables-exercises.js +++ b/data-and-variables/exercises/data-and-variables-exercises.js @@ -1,11 +1,35 @@ // Declare and assign the variables below +let spaceShuttle = "Determination"; +let shuttleSpeed = 17500; +let distanceToMars = 225000000; +let distanceToMoon = 384000; +const mpk = 0.621; + // Use console.log to print the 'typeof' each variable. Print one item per line. +console.log(typeof spaceShuttle); +console.log(typeof shuttleSpeed); +console.log(typeof distanceToMars); +console.log(typeof distanceToMoon); +console.log(typeof mpk); + // Calculate a space mission below +let milesToMars = distanceToMars * mpk; +let hoursMars = milesToMars / shuttleSpeed; +let daysMars = hoursMars / 24; + // Print the results of the space mission calculations below +console.log(spaceShuttle + " will take " + daysMars + " days to reach Mars."); + // Calculate a trip to the moon below -// Print the results of the trip to the moon below \ No newline at end of file +let milesToMoon = distanceToMoon * mpk; +let hoursMoon = milesToMoon / shuttleSpeed; +let daysMoon = hoursMoon / 24; + +// Print the results of the trip to the moon below + +console.log(spaceShuttle + " will take " + daysMoon + " days to reach the Moon."); \ No newline at end of file diff --git a/dom-and-events/exercises/script.js b/dom-and-events/exercises/script.js index de6b630519..b397c7b2a7 100644 --- a/dom-and-events/exercises/script.js +++ b/dom-and-events/exercises/script.js @@ -5,6 +5,24 @@ function init () { // Put your code for the exercises here. + button.addEventListener("click", (e) => { + paragraph.innerHTML = "Houston, we have liftoff!"; + }); + + missionAbort.addEventListener("mouseover", (e) => { + missionAbort.style.backgroundColor = "red"; + }); + + missionAbort.addEventListener("mouseleave", (e) => { + missionAbort.style.backgroundColor = ""; + }); + + missionAbort.addEventListener("click", (e) => { + let response = window.confirm("Are you sure you want to abort the mission?"); + if (response) { + paragraph.innerHTML = "Mission aborted! Space shuttle returning home"; + } + }); } window.addEventListener("load", init); diff --git a/dom-and-events/studio/scripts.js b/dom-and-events/studio/scripts.js index 45c9b3a9d1..d5325c193f 100644 --- a/dom-and-events/studio/scripts.js +++ b/dom-and-events/studio/scripts.js @@ -1,2 +1,76 @@ // Write your JavaScript code here. // Remember to pay attention to page loading! + +window.addEventListener('load', () => { + const rocket = document.getElementById('rocket'); + + const liftOffBtn = document.getElementById('takeoff'); + const landBtn = document.getElementById('landing'); + const abortBtn = document.getElementById('missionAbort'); + + const upButton = document.getElementById('up'); + const downButton = document.getElementById('down'); + const rightButton = document.getElementById('right'); + const leftButton = document.getElementById('left'); + + const flightStat = document.getElementById('flightStatus'); + const shuttleBackground = document.getElementById('shuttleBackground'); + const shuttleHeight = document.getElementById('spaceShuttleHeight'); + + liftOffBtn.addEventListener('click', function (e) { + let response = window.confirm('Confirm that the shuttle is ready for takeoff.'); + + if (response) { + flightStat.innerHTML = 'Shuttle in flight.'; + shuttleBackground.style.backgroundColor = "blue"; + shuttleHeight.innerHTML = 10000; + } + }) + + landBtn.addEventListener('click', e => { + window.alert('The shuttle is landing. Landing gear engaged.'); + + flightStat.innerHTML = 'The shuttle has landed'; + shuttleBackground.style.backgroundColor = "green"; + shuttleHeight.innerHTML = 0; + rocket.style.top = '50%'; + rocket.style.left = '50%'; + }) + + abortBtn.addEventListener('click', e => { + let response = window.confirm('Confirm that you want to abort the mission.'); + + if (response) { + flightStat.innerHTML = 'Mission aborted.'; + shuttleBackground.style.backgroundColor = "green"; + shuttleHeight.innerHTML = 0; + rocket.style.top = '50%'; + rocket.style.left = '50%'; + } + }) + + upButton.addEventListener('click', function () { + moveRocket(0, -10); + shuttleHeight.innerText = parseInt(shuttleHeight.innerText) + 10000; + }); + downButton.addEventListener('click', function () { + moveRocket(0, 10); + shuttleHeight.innerText = parseInt(shuttleHeight.innerText) - 10000; + if (shuttleHeight <= 0) { + shuttleHeight.innerHTML = 0; + } + }); + leftButton.addEventListener('click', function () { + moveRocket(-10, 0); + }); + rightButton.addEventListener('click', function () { + moveRocket(10, 0); + }); + function moveRocket(dx, dy) { + let left = parseInt(rocket.style.left.replace('px', '')) + dx; + let top = parseInt(rocket.style.top.replace('px', '')) + dy; + rocket.style.paddingLeft = `${left}px`; + rocket.style.paddingTop = `${top}px`; + } + +}) \ No newline at end of file diff --git a/dom-and-events/studio/styles.css b/dom-and-events/studio/styles.css index cc932dd89d..23f1a07c0d 100644 --- a/dom-and-events/studio/styles.css +++ b/dom-and-events/studio/styles.css @@ -27,4 +27,11 @@ .centered { text-align: center; +} + +#rocket { + position: absolute; + left: 50%; + top: 50%; + transform: translate(-50%, -50%); } \ No newline at end of file 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/DebuggingLogicErrors1.js b/errors-and-debugging/exercises/DebuggingLogicErrors1.js index 1ad473f08d..9b40824f8f 100644 --- a/errors-and-debugging/exercises/DebuggingLogicErrors1.js +++ b/errors-and-debugging/exercises/DebuggingLogicErrors1.js @@ -3,6 +3,8 @@ // Did it? // Do not worry about fixing the code yet, we will do that in the next series of exercises. +// The shuttle should NOT have launched, but it did launch. + let launchReady = false; let fuelLevel = 17000; let crewStatus = true; diff --git a/errors-and-debugging/exercises/DebuggingLogicErrors2.js b/errors-and-debugging/exercises/DebuggingLogicErrors2.js index 160a0c2cd0..0390f01452 100644 --- a/errors-and-debugging/exercises/DebuggingLogicErrors2.js +++ b/errors-and-debugging/exercises/DebuggingLogicErrors2.js @@ -4,6 +4,8 @@ //Given the fuelLevel value, should launchReady be true or false after the check? Is the program behaving as expected? +// launchReady should be false after the check. Program is running as expected. + let launchReady = false; let fuelLevel = 17000; // let crewStatus = true; @@ -17,6 +19,8 @@ if (fuelLevel >= 20000) { launchReady = false; } +console.log(launchReady); + // if (crewStatus && computerStatus === 'green'){ // console.log('Crew & computer cleared.'); // launchReady = true; diff --git a/errors-and-debugging/exercises/DebuggingLogicErrors3.js b/errors-and-debugging/exercises/DebuggingLogicErrors3.js index 023f2ab07d..fa7338d897 100644 --- a/errors-and-debugging/exercises/DebuggingLogicErrors3.js +++ b/errors-and-debugging/exercises/DebuggingLogicErrors3.js @@ -5,6 +5,9 @@ // Given the values for crewStatus and computerStatus, should launchReady be true or false after the check? // Is the program behaving as expected? +// Given the values for crewStatus and computerStatus, launchReady will be true. +// Without fuelLevel in mind, the program is behaving as expected. + let launchReady = false; // let fuelLevel = 17000; let crewStatus = true; @@ -26,6 +29,8 @@ if (crewStatus && computerStatus === 'green'){ launchReady = false; } +console.log(launchReady); + // if (launchReady) { // console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...'); // console.log('Liftoff!'); diff --git a/errors-and-debugging/exercises/DebuggingLogicErrors4.js b/errors-and-debugging/exercises/DebuggingLogicErrors4.js index dc9ac0af9d..6e8de640e0 100644 --- a/errors-and-debugging/exercises/DebuggingLogicErrors4.js +++ b/errors-and-debugging/exercises/DebuggingLogicErrors4.js @@ -4,6 +4,9 @@ // Given the values for fuelLevel, crewStatus and computerStatus, should launchReady be true or false? // Is the program behaving as expected? +// After checking fuelLevel, crewStatus, and computerStatus, the variable launchReady will be true. +// Program will run as told. If we want both if-statements to be be true, then program will not run as expected. + let launchReady = false; let fuelLevel = 17000; let crewStatus = true; diff --git a/errors-and-debugging/exercises/DebuggingLogicErrors5.js b/errors-and-debugging/exercises/DebuggingLogicErrors5.js index 7eb908e769..88260b3ba5 100644 --- a/errors-and-debugging/exercises/DebuggingLogicErrors5.js +++ b/errors-and-debugging/exercises/DebuggingLogicErrors5.js @@ -3,6 +3,7 @@ // Refactor the code to do this. Verify that your change works by updating the console.log statements. let launchReady = false; +let launchReady2 = false; let fuelLevel = 17000; let crewStatus = true; let computerStatus = 'green'; @@ -19,10 +20,17 @@ console.log("launchReady = ", launchReady); if (crewStatus && computerStatus === 'green'){ console.log('Crew & computer cleared.'); - launchReady = true; + launchReady2 = true; } else { console.log('WARNING: Crew or computer not ready!'); - launchReady = false; + launchReady2 = false; } -console.log("launchReady = ", launchReady); \ No newline at end of file +console.log("launchReady2 = ", launchReady2); + +if (launchReady && launchReady2) { + console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...'); + console.log('Liftoff!'); +} else { + console.log('Launch scrubbed.'); +} \ No newline at end of file diff --git a/errors-and-debugging/exercises/DebuggingRuntimeErrors1.js b/errors-and-debugging/exercises/DebuggingRuntimeErrors1.js index e66e494a30..7bbf7ebb82 100644 --- a/errors-and-debugging/exercises/DebuggingRuntimeErrors1.js +++ b/errors-and-debugging/exercises/DebuggingRuntimeErrors1.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/DebuggingRuntimeErrors2.js b/errors-and-debugging/exercises/DebuggingRuntimeErrors2.js index a656080d25..703a0d61c4 100644 --- a/errors-and-debugging/exercises/DebuggingRuntimeErrors2.js +++ b/errors-and-debugging/exercises/DebuggingRuntimeErrors2.js @@ -14,7 +14,7 @@ if (launchReady) { console.log("Fed parrot..."); console.log("6, 5, 4..."); console.log("Ignition..."); - consoul.log("3, 2, 1..."); + console.log("3, 2, 1..."); console.log("Liftoff!"); } else { console.log("Launch scrubbed."); diff --git a/errors-and-debugging/exercises/DebuggingSyntaxErrors2.js b/errors-and-debugging/exercises/DebuggingSyntaxErrors2.js index b600339254..daf36e5da5 100644 --- a/errors-and-debugging/exercises/DebuggingSyntaxErrors2.js +++ b/errors-and-debugging/exercises/DebuggingSyntaxErrors2.js @@ -8,7 +8,7 @@ let launchReady = false; let crewStatus = true; let computerStatus = 'green'; -if (crewStatus &&& computerStatus === 'green'){ +if (crewStatus && computerStatus === 'green'){ console.log('Crew & computer cleared.'); launchReady = true; } else { @@ -17,7 +17,7 @@ if (crewStatus &&& computerStatus === 'green'){ } if (launchReady) { - console.log(("10, 9, 8, 7, 6, 5, 4, 3, 2, 1..."); + console.log("10, 9, 8, 7, 6, 5, 4, 3, 2, 1..."); console.log("Fed parrot..."); console.log("Ignition..."); console.log("Liftoff!"); diff --git a/exceptions/exercises/divide.js b/exceptions/exercises/divide.js index 06fc889862..c47172ba0f 100644 --- a/exceptions/exercises/divide.js +++ b/exceptions/exercises/divide.js @@ -5,3 +5,13 @@ // However, if the denominator is zero you should throw the error, "Attempted to divide by zero." // Code your divide function here: + +let divide = (numerator, denominator) => { + if (denominator === 0) { + throw Error("Attempted to divide by zerio."); + } + + return numerator / denominator; +} + +console.log(divide(5,0)); \ No newline at end of file diff --git a/exceptions/exercises/test-student-labs.js b/exceptions/exercises/test-student-labs.js index cfe5bfe175..f8f6ffbac3 100644 --- a/exceptions/exercises/test-student-labs.js +++ b/exceptions/exercises/test-student-labs.js @@ -1,7 +1,12 @@ function gradeLabs(labs) { - for (let i=0; i < labs.length; i++) { + for (let i = 0; i < labs.length; i++) { let lab = labs[i]; - let result = lab.runLab(3); + let result; + try { + result = lab.runLab(3); + } catch (err) { + result = "Error thrown"; + } console.log(`${lab.student} code worked: ${result === 27}`); } } @@ -10,15 +15,38 @@ let studentLabs = [ { student: 'Carly', runLab: function (num) { - return Math.pow(num, num); + return Math.pow(num, num); } }, { student: 'Erica', runLab: function (num) { - return num * num; + return num * num; } } ]; gradeLabs(studentLabs); + +let studentLabs2 = [ + { + student: 'Blake', + myCode: function (num) { + return Math.pow(num, num); + } + }, + { + student: 'Jessica', + runLab: function (num) { + return Math.pow(num, num); + } + }, + { + student: 'Mya', + runLab: function (num) { + return num * num; + } + } +]; + +gradeLabs(studentLabs2); \ No newline at end of file diff --git a/fetch/exercises/fetch_planets.html b/fetch/exercises/fetch_planets.html new file mode 100644 index 0000000000..3e1e3d67da --- /dev/null +++ b/fetch/exercises/fetch_planets.html @@ -0,0 +1,43 @@ + + + + +Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque, ut minima. Assumenda excepturi repudiandae voluptates libero sed fugiat quam odit earum blanditiis? Sint sapiente nihil officiis illo dolorum quibusdam dicta! Lorem ipsum dolor sit, amet consectetur adipisicing elit. Deserunt officia sint incidunt eum quis atque voluptates sit consequatur nihil, perspiciatis tempore autem dicta officiis voluptatum, laboriosam delectus dolorem aperiam accusantium. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nemo eum quibusdam nisi esse, soluta explicabo eveniet ad molestias modi nulla natus dolores sapiente expedita! Enim maiores et sed ipsum temporibus! Lorem, ipsum dolor sit amet consectetur adipisicing elit. Neque voluptatum reiciendis quidem similique nulla facilis dolorum consectetur? Repudiandae, temporibus? Qui, placeat? Vitae repellendus earum saepe velit, expedita nemo enim. Enim. Lorem ipsum dolor sit amet consectetur adipisicing elit. Rem facilis, maiores, sint amet ut odio aliquam fugiat nam debitis accusamus beatae. Alias unde quidem totam quaerat, quas ab laudantium magni?
+Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime, impedit quas molestiae quo repudiandae dolorem dignissimos, quisquam adipisci maiores fuga distinctio incidunt ex, tenetur earum asperiores quae provident quidem veniam? Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ex tempora sed temporibus qui illum mollitia amet ducimus aliquam, minus voluptas ipsam dicta delectus. Similique sed, veritatis nulla natus consequuntur ullam? Lorem ipsum dolor sit amet consectetur adipisicing elit. Incidunt officiis, repellendus vitae soluta dolor voluptatibus earum exercitationem perferendis architecto odit eos consequuntur maiores ipsum! Aliquid incidunt reiciendis quaerat consectetur impedit? Lorem ipsum dolor sit amet consectetur adipisicing elit. Nemo, voluptatem dignissimos inventore pariatur sapiente nisi consequatur facere soluta, incidunt nam asperiores? Libero illo impedit aut obcaecati, odit excepturi tempora! Dolorem? Lorem ipsum dolor sit amet consectetur adipisicing elit. Sit eius eveniet tempora blanditiis quibusdam nihil aperiam fugiat minima. Ipsam quis quisquam natus accusantium assumenda voluptatum itaque, deleniti dolores nemo molestias?
+Lorem ipsum dolor sit, amet consectetur adipisicing elit. At ad quod aut obcaecati nam laborum repellendus aperiam repudiandae excepturi rem voluptate nobis perferendis, atque illum nisi deleniti esse dolores autem. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos autem placeat aperiam dicta temporibus, sunt expedita, vel deserunt libero vitae ipsa quasi vero deleniti voluptatum perspiciatis consectetur molestias veritatis! Corrupti? Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere, sunt perferendis sint doloribus eius sequi similique. Adipisci distinctio atque dolorem officiis voluptatibus, repellat sit maiores consequuntur molestias corporis at numquam? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus, exercitationem explicabo saepe temporibus aspernatur cumque est corporis eligendi obcaecati tempora et assumenda repellat natus? Autem voluptas repudiandae explicabo doloremque qui. Lorem ipsum dolor sit amet consectetur adipisicing elit. Quae fugit voluptatibus ratione error nostrum libero atque illum natus mollitia asperiores. Necessitatibus corrupti error nihil veniam aliquid, alias pariatur quod facere!