submitting Homework 1 #2

Merged
merged 1 commit into from Nov 30, 2018

Conversation

Projects
None yet
2 participants
@norbs
Contributor

norbs commented Nov 28, 2018

No description provided.

@vodnik

vodnik approved these changes Nov 30, 2018


for(i = 99; i > 0; ) {
if(i > 2) {
console.log(`${i} bottles of beer on the wall, ${i} bottles of beer.\nTake one down and pass it around, ${--i} bottles of beer on the wall.`);

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

Great use of template literals!

if(i > 2) {
console.log(`${i} bottles of beer on the wall, ${i} bottles of beer.\nTake one down and pass it around, ${--i} bottles of beer on the wall.`);
} else if(i === 2) {
console.log(`${i} bottles of beer on the wall, ${i} bottles of beer.\nTake one down and pass it around, ${--i} bottle of beer on the wall.`);

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

Clever that you're relying on your console.log statements to decrement i! This works, but I'd argue for leaving the i-- in the first line, and instead using i-1 as the value in the second part of each statement. This makes the code self-documenting, so I can more clearly see the structure of the for loop in the first line. But you're also allowed to have your own style!

i--;
}
}
console.log("No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.")

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

Again, this is a totally valid way to write this and it gets the job done. I think enclosing this in a final else statement would make your intention clearer -- that this is the final fallback for the if/else construction above.

let zip = [00211, 98660, 44001, 99001, 14030];

//Returns a random integer between 0 and max
function getRandomInt(max) {

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

I love that you broke this out into its own function for reuse.


//Returns a random element from within the array
function getRandomElement(array) {
return array[getRandomInt(array.length)];

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

Brilliant use of array.length!

@vodnik vodnik merged commit 3fc5aee into vodnik:master Nov 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment