Created
May 9, 2023 23:27
-
-
Save kironroy/6556a8ac34b788bda2eb458d455b8f4d to your computer and use it in GitHub Desktop.
Code Challenge Temp js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CODE CHALLENGE | |
// Given an array of forecasted maximum temperatures, the thermometer displays a | |
// string with the given temperatures. Example: [17, 21, 23] will print "... 17ºC in 1 | |
// days ... 21ºC in 2 days ... 23ºC in 3 days ..." | |
// Your tasks: | |
// 1. Create a function 'printForecast' which takes in an array 'arr' and logs a | |
// string like the above to the console. Try it with both test datasets. | |
// 2. Use the problem-solving framework: Understand the problem and break it up | |
// into sub-problems! | |
// Test data: | |
// § Data 1: [17, 21, 23] | |
// § Data 2: [12, 5, -5, 0, 4] | |
// 1. Understand the problem | |
// - Given numbers, but return a string | |
// - Working with two sets of data | |
// - Adding a dynamically changing day with the temp | |
// 2. Breaking up into sub-problems | |
// - two sets of data -> create two arrays | |
// - create a function called printForecast that logs a string value | |
// - the function takes a number and returns a string | |
// - two strings have to combined? The later | |
// - for loop | |
// - another for loop? | |
// DAY NEEDS TO DYNAMICALLY CHANGE WITH CORRESPONDING TEMP! | |
// Pseudocode | |
// arrays | |
const dataOneArr = [17, 21, 23]; | |
const dataTwoArr = [12, 5, -5, 0, 4]; | |
const dataOneAndTwoArr = dataOneArr.concat(dataTwoArr); | |
// function | |
function myFunction(yourString) { | |
console.log(' '); | |
console.log(yourString); | |
console.log(' '); | |
} | |
// let day = 0; | |
const printForecast = function (arr) { | |
let day = 0; | |
do { | |
// console.log(day); | |
day++; | |
} while (day < arr); | |
for (let j = 0; j < arr.length; j++) { | |
console.log(`${arr[j]} C\xB0 in ${day++} days... `); | |
} | |
}; | |
myFunction('* Array 1 *'); | |
printForecast(dataOneArr); | |
myFunction('* Array 2 *'); | |
printForecast(dataTwoArr); | |
myFunction('* Array 3 *'); | |
printForecast(dataOneAndTwoArr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment