Created
March 17, 2022 18:42
-
-
Save riccardogiorato/88c68725163f33b46147bcdc0cac9b1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// STEPS to solve a problem: | |
// 1. define what are the input variables | |
// 2. what is the output format or the result | |
// 3. define what constants are in the problem? | |
// 3. (not always) Find the solution the real world if you had to give these instruction to a group of kids | |
// 4. Reverse engineer the ouput from input | |
// INPUT variables for the room size | |
// l = number, lenght of the room in m | |
// h = number, height of the room in m | |
// w = number, width of the room in m | |
// OUTPUT of the function | |
// return string = number of rools the user must buy | |
function wallpaper(l, w, h) { | |
const numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve","thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"]; | |
if(l==0 || w==0 || h== 0) return numbers[0]; | |
// extra length to buy | |
const percentageToBuy = 1.15; //100% + 15% | |
const widthRolls = 0.52; //m or 52cm | |
const lengthRolls = 10; //m | |
const sizeRoom = (2* w*h) + (2* l*h); | |
const sizeRoll = widthRolls*lengthRolls; | |
const rolls = Math.ceil((sizeRoom / sizeRoll) * percentageToBuy); | |
if(rolls > 20) rolls = 20; | |
return numbers[rolls]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment