submitting Homework 1 #3

Merged
merged 1 commit into from Nov 30, 2018
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+771 −0
Diff settings

Always

Just for now

submitting Homework 1

  • Loading branch information...
Anna Kalil
Anna Kalil committed Nov 28, 2018
commit e30f8c5ebfbaf0b4aa4219a6aa60961d237e4dcf
@@ -0,0 +1,41 @@
/*
Write code that prints the lyrics to "99 Bottles of Beer on the Wall" to the
console.
If you're unfamiliar with the song, you can find the lyrics here:
http://www.99-bottles-of-beer.net/lyrics.html.
Be sure that all of your output includes proper spacing (no words or values
running into each other).
Hint: You can make your output appear on multiple lines by using the string \n
to insert a line break.
BONUS: For an extra challenge, improve this code to print "1 bottle" rather
than "1 bottles" as well as the special lyrics for no bottles remaining (Hint:
read up on if/else conditional statements at https://mdn.io/if...else).
*/




// for (i = 99; i > 0; i--) {
// let bottles = 'bottles';

// console.log(i + ' ' + bottles + ' of beer on the wall, ' + i + ' bottles of beer. \n Take one down and pass it around, ' + (i - 1) + ' ' + bottles + ' of beer on the wall.');
// };


for (i = 99; i >= 0; i--) {
let bottles = 'bottles';

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

Great idea to abstract the singular/plural word here. It seems possible for there to be some confusion here between the variable name ('bottles') and the potential values (either 'bottle' or 'bottles'), so I'd suggest in the future choosing a variable name that's not the same as its value -- something like bottleWord here, for instance.


if ((i > 1)) {
console.log(i + ' ' + bottles + ' of beer on the wall, ' + i + ' ' + bottles + ' of beer. \n Take one down and pass it around, ' + (i - 1) + ' ' + bottles + ' of beer on the wall.');
} else if ((i === 1)) {
bottles = 'bottle';
console.log(i + ' ' + bottles + ' of beer on the wall, ' + i + ' ' + bottles + ' of beer. \n Take one down and pass it around, no more bottles of beer on the wall.');
} else if ((i === 0)) {

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

Your if/else if logic is solid. Here I'd suggest leaving off the final if and condition, because if the loop reaches this code, there's no value possible except 0, right?

console.log('No more bottles of beer on the wall, no more bottles of beer. \n Go to the store and buy some more, 99 bottles of beer on the wall.' + String.fromCodePoint(0x1F37b));

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

The icon is a nice touch. I love that you went the extra mile to do that!

};
};

// without hardcoding bottle/bottles in the string - could have created an array
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<!-- js -->
<script src="app.js"></script>
</body>
</html>
@@ -0,0 +1,46 @@
/*
Write code that generates random addresses
Each time you load or reload the page in a browser, your program should log
a new randomly-generated address to the console.
Step 1:
Create arrays that contain dummy data for each of the following:
street number, street name, city name, state name, and zip code
Step 2:
Write code that randomly selects one item from each of these arrays, uses
the selected values to construct a string containing a random address, and
then logs the result to the console.
Step 3:
Save your work, load your app in the browser, open the console, and verify
that a random address is logged.
Step 4:
Reload the page and verify that a different random address is logged.
Example output:
34578 Dolphin Street, Wonka NY, 44506
*/

// Step 1: Array with dummy data
let numbers = [62, 494, 662, 780, 772, 512];

let streets = ['27th Avenue', 'Hilltop Terrace', 'Pine Ridge Road', 'Commonwealth Avenue', 'Bryant Street', 'Market Street'];

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

Comm Ave! 🎓


let cities = ['San Francisco', 'Boston', 'Waban', 'Alexandria', 'Minneapolis', 'Chicago'];

let states = ['CA', 'VA', 'MA', 'IL', 'MN', 'WV'];

let zips = [94121, 22301, 94107, '02468', '02446', '02115'];

This comment has been minimized.

@vodnik

vodnik Nov 30, 2018

Owner

Note that you included a combination of numbers and strings here in the zips array. Given that you're concatenating values into a string, I'd suggest using all strings here.


// Step 2 Part 1: Write code that randomly selects one item from each of these arrays
let randomNumber = numbers[(Math.floor(Math.random() * numbers.length))];
let randomStreet = streets[(Math.floor(Math.random() * streets.length))];
let randomCity = cities[Math.floor(Math.random() * cities.length)];
let randomState = states[Math.floor(Math.random() * states.length)];
let randomZip = zips[Math.floor(Math.random() * zips.length)];


// Step 2 Part 2: Write code that uses the selected values to construct a string containing a random address and logs the result to the console.
console.log(randomNumber + ' ' + randomStreet + ', ' + randomCity + ' ' + randomState + ', ' + randomZip);
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<!-- js -->
<script src="app.js"></script>
</body>
</html>
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.