Permalink
Browse files

Merge pull request #2 from norbs/master

submitting Homework 1
  • Loading branch information...
vodnik committed Nov 30, 2018
2 parents 38b27ce + 93570eb commit 3fc5aee904f1d6dafc714340b69c8114bb9815c1
@@ -0,0 +1,32 @@
/*
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; ) {
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.`);
} else if(i === 1) {
console.log(`${i} bottle of beer on the wall, ${i} bottle of beer.\nTake one down and pass it around, no bottles of beer on the wall.`);
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.")


//99 bottles of beer on the wall, 99 bottles of beer.
//Take one down and pass it around, 98 bottles of beer on the wall.
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<!-- js -->
<script src="app.js"></script>
</body>
</html>
@@ -0,0 +1,51 @@
/*
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
*/

//Dataset
let streetNumber = [123, 99, 118, 4503, 1788];
let streetName = ['W. 12th Avenue', 'Blueberry Lane', 'Guerrero Street', 'Park Avenue', 'Balaclava Avenue', 'King Edward Avenue', 'Cambie Street', 'Granville Street', 'Robson Street'];
let cityName = ['Vancouver', 'New Holland', 'Albuquerque', 'Springfield', 'Santa Fe'];
let stateName = ['WA', 'CA', 'NY', 'IL', 'WY', 'AZ'];
let zip = [00211, 98660, 44001, 99001, 14030];

//Returns a random integer between 0 and max
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
};

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

//Pick a random element from each array
let myStreetNumber = getRandomElement(streetNumber);
let myStreetName = getRandomElement(streetName);
let myCityName = getRandomElement(cityName);
let myStateName = getRandomElement(stateName);
let myZip = getRandomElement(zip);

//Concat and output the set of random address elements
console.log(myStreetNumber + ' ' + myStreetName + ', ' + myCityName + ' ' + myStateName + ', ' + myZip);
@@ -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 3fc5aee

Please sign in to comment.