Skip to content

Instantly share code, notes, and snippets.

@0xCourtney
0xCourtney / 1.2.js
Created March 26, 2018 15:46
FizzBuzz - Toy Problem
// FizzBuzz
// write a function that takes in one number.
// Starting at 1, console log every number up to the number passed in.
// If the number being logged is divisible by 3 log 'Fizz' instead.
// If the number is divisible by 5 we will log 'Buzz' instead.
// If they are divisible by both 3 and 5 we will log 'FizzBuzz'
function fizzBuzz(num) {
for (let i = 1; i <= num; i++) {
if (i % 3 === 0 && i % 5 === 0) {
@0xCourtney
0xCourtney / 2.1.js
Created March 26, 2018 15:45
DiceRoll - ToyProblem
// Create a function that returns the result of a dice roll
// Then modify the function to accept rolling multiple dice of the same size and return the cumulative sum of .
// Then modify the function to return an array of objects containing the cumulative sum at the current roll, the dice roll value, and the index.
function diceRoll(size = 6, numDice) {
let diceSum = 0;
let diceArr = [];
for (let i = 0; i < numDice; i++) {
let roll = Math.floor(Math.random() * (size - 1) + 1);
quote = '"A person who never made a mistake never tried anything new"'
quotee = "- Albert Einstein"
print(quote +"\n"+ quotee)