Created
April 15, 2018 00:37
-
-
Save ogryzek/8bb1fd1ceb317e79135ee91b48d5e096 to your computer and use it in GitHub Desktop.
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
// 1.) Write a function `cigs()` that takes an argument `perHour`, and | |
// logs "You smoke (however many perHour) cigs per hour." | |
function cigs(perHour) { | |
first = "You smoke "; | |
middle = perHour; | |
last = " cigs per hour."; | |
msg = first + middle + last; | |
console.log(msg); | |
} | |
function cigs(perHour) { | |
console.log("You smoke " + perHour + " cigs per hour."); | |
} | |
// 2.) Write a function `cigs()` that takes an argument `perHour`, and | |
// logs: | |
// • "You smoke (however many perHour) cigs per hour." | |
// • "You smoke (however many <for a day>) cigs per day." | |
// • "You smoke (however many <for a week>) cigs per week." | |
// • "You smoke (however many <for a month>) cigs per month." | |
// • "You smoke (however many <for a year>) cigs per year." | |
function cigs(perHour) { | |
day = 24; | |
dayWithSleep = day - 8; | |
weekWithSleep = dayWithSleep * 7; | |
monthWithSleep = dayWithSleep * 30; | |
yearWithSleep = weekWithSleep * 52; | |
perDay = perHour * dayWithSleep; | |
perWeek = perHour * weekWithSleep; | |
perMonth = perHour * monthWithSleep; | |
perYear = perHour * yearWithSleep; | |
console.log("You smoke " + perHour + " cigs per hour."); | |
console.log("You smoke " + perDay + " cigs per day."); | |
console.log("You smoke " + perWeek + " cigs per week."); | |
console.log("You smoke " + perMonth + " cigs per month."); | |
console.log("You smoke " + perYear + " cigs per year."); | |
} | |
// 3.) Write a function `increase` that takes two arguments `currentCount`, | |
// and `increaseBy` and returns the result of increasing the current count | |
// by the amount entered in `increaseBy`. | |
function increase(currentCount, increaseBy) { | |
result = currentCount + increaseBy; | |
return result; | |
} | |
// 4.) write a function that logs each integer between 1 and 100 to the console. | |
function logOneHundred() { | |
end = 100; | |
current = 1; | |
while(current <= end ) { | |
console.log(current); | |
current++; | |
} | |
} | |
function logOneHundred() { | |
end = 100; | |
current = 1; | |
for (var i = current; i <= end; i++) { | |
console.log(i); | |
} | |
} | |
// 5.) Modify the above function to iterateratively (in increments of 1), increase | |
// the count by the value of `increaseBy` and return the result. | |
function increase(currentCount, increaseBy) { | |
result = currentCount; | |
desiredCount = currentCount + increaseBy; | |
while (result <= desiredCount) { | |
result++; | |
} | |
return result; | |
} | |
// 6.) Modify the above function to log "I got five on it!" to the console, whenever | |
// the count is incremented to a number that is a multiple of five. | |
function increase(currentCount, increaseBy) { | |
result = currentCount; | |
desiredCount = currentCount + increaseBy; | |
while (result < desiredCount) { | |
remainder = result % 5; | |
if (remainder == 0) { | |
console.log("I got five on it!"); | |
} | |
result++; | |
} | |
return result; | |
} | |
increase(0, 20) | |
// 7.) Write a function that takes a number as an argument. The | |
// function should log every number from 1 up to the number | |
// passed in as an argument, however | |
// | |
// • if the number is a multiple of 3, instead of logging | |
// the number, log "Fizz" | |
// • if the number is a multiple of 5, instead of logging | |
// the number, log "Buzz" | |
// • if the number is a multiple of both 3 and 5, log | |
// "FizzBuzz" instead of the number. | |
function fizzBuzz(number) { | |
start = 1; | |
while (start <= number) { | |
// if(start % 3 == 0 && start % 5 == 0) { | |
if(start % 15 == 0) { | |
console.log("FizzBuzz"); | |
} else if (start % 3 == 0) { | |
console.log("Fizz"); | |
} else if (start % 5 == 0) { | |
console.log("Buzz"); | |
} else { | |
console.log(start); | |
} | |
start++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment