Skip to content

Instantly share code, notes, and snippets.

@diklein
Created October 1, 2016 01:13
Show Gist options
  • Save diklein/de162e260f87577d331457d2b2faecda to your computer and use it in GitHub Desktop.
Save diklein/de162e260f87577d331457d2b2faecda to your computer and use it in GitHub Desktop.
JSD4 - Homework 2
var startupX = ['Uber', 'Google', 'Amazon', 'Apple', 'Facebook', 'Twitter'];
var startupY = ['Slack', 'Trello', 'Tesla', 'Hyperloop', 'Harvest'];
var startupIdea;
var favorites = [];
var startup = document.querySelector('.startup');
var generate = document.querySelector('.generate');
var save = document.querySelector('.save');
var print = document.querySelector('.print');
var list = document.querySelector('.list');
generate.addEventListener('click', generateStartup);
save.addEventListener('click', saveFavorite);
print.addEventListener('click', printFavorites);
generateStartup();
function generateStartup() {
var random1 = Math.floor(Math.random() * startupX.length);
var random2 = Math.floor(Math.random() * startupY.length);
startupIdea = "A startup that is " + startupX[random1] + ", but for " + startupY[random2];
startup.innerHTML = startupIdea;
}
function saveFavorite() {
favorites.push(startupIdea);
}
function printFavorites() {
list.innerHTML = '';
var favoritesText = "";
for (var i = 0; i < favorites.length; i++) {
favoritesText = favoritesText + favorites[i] + "<br/>";
}
list.innerHTML = favoritesText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment