Permalink
Browse files

Merge pull request #3 from ackalil/master

submitting Homework 1
  • Loading branch information...
vodnik committed Nov 30, 2018
2 parents 3fc5aee + e30f8c5 commit 786f83946c489e994de4fc1fd5158adf18dee4af
@@ -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';

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)) {
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));
};
};

// 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'];

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'];

// 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.

0 comments on commit 786f839

Please sign in to comment.