Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kyle Easton's Homework - 11/29/17 #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions challenges/bottles-of-beer-song.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@
*/

// YOUR CODE HERE

let question = prompt("How many verses do you want to hear?", "Enter a number less than 100");


for (var i = question; i >= 0; i -=1) {
if (i > 2) {
console.log(i + " bottles of beer on the wall, " + i + " bottles of beer! Take one down, pass it around, " + (i-1) + " bottles of beer on the wall!");
} else if (i ===2) {
console.log(i + " bottles of beer on the wall, " + i + " bottles of beer! Take one down, pass it around, " + (i-1) + " bottle of beer on the wall!");
} else if (i === 1) {
console.log(i + " bottle of beer on the wall, " + i + " bottle of beer! Take one down, pass it around, no more bottles of beer on the wall!");
} else if (i === 0) {
console.log(i + " bottles of beer on the wall, " + i + " bottles of beer! None to take down, none to pass it around, no more bottles of beer on the wall!");
}
}
14 changes: 14 additions & 0 deletions challenges/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Insult Maker</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div>
<h1>What is the insult?</h1>
</div>

</body>
<script src="shakespearian-insult-generator.js"></script>
</html>
18 changes: 18 additions & 0 deletions challenges/palindrome-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@
*/

// YOUR CODE HERE

var isPalindrome = function (word) {
let arrayOfLetters = word.split("");
for (let i = 0; i <= arrayOfLetters.length; i++) {
if(arrayOfLetters[i] === arrayOfLetters[(arrayOfLetters.length - (i + 1))]) {
console.log(true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we talk about functions more tomorrow & next week, we'll talk about why console.log is less useful here than using return, but it's good that you got this working!

} else {
console.log(false);
}
}

}

isPalindrome("mom");




22 changes: 22 additions & 0 deletions challenges/primes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,25 @@
*/

// YOUR CODE HERE

//1.

let isPrime = function(num) {
if (num === 2 || num % 2 === 1) {
console.log(true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, here it would be better to return this answer rather than console.loging it.

} else {
console.log(false);
}
}

//2.

let primes = function(max) {
let primeArray = [];
for (let i = 2; i <= max; i++) {
if (i === 2 || i % 2 === 1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this will add every odd number to your list of primes--remember to test on lots of interesting cases!

primeArray.push(i);
}
}
console.log(primeArray);
}
24 changes: 24 additions & 0 deletions challenges/shakespearian-insult-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,27 @@ var second_word = ["weather-bitten", "unchin-snouted", "toad-spotted", "tickle-b
var third_word = ["wagtail", "whey-face", "vassal", "varlet", "strumpet", "skainsmate", "scut", "ratsbane", "pumpion", "puttock", "pignut", "pigeon-egg", "nut-hook", "mumble-news", "moldwarp", "miscreant", "minnow", "measle", "mammet", "malt-worm", "maggot-pie", "lout", "lewdster", "joithead", "hugger-mugger", "horn-beast", "hedge-pig", "harpy", "haggard", "gudgeon", "giglet", "fustilarian", "foot-licker", "flirt-gill", "flax-wench", "flap-dragon", "dewberry", "death-token", "codpiece", "coxcomb", "clotpole", "clack-dish", "canker-blossom", "bum-bailey", "bugbear", "boar-pig", "bladder", "barnacle", "baggage", "apple-john"];

// YOUR CODE HERE


let generateInsult = function() {
var result;
let randOne = first_word[(Math.random() * first_word.length) | 0];
let randTwo = second_word[(Math.random() * second_word.length) | 0];
let randThree = third_word[(Math.random() * third_word.length) | 0];

let askName = prompt("Who is this scoundrel that needs insulting?", "Enter a name");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense you needed to add the HTML page to get these prompts to work--nice job going beyond the directions to complete the bonus.

let numOfInsults = prompt("How many insults to give?", "Enter a number up to 3");
if(numOfInsults === "1") {
result = askName + ", you are " + randOne + "!";
} else if (numOfInsults === "2") {
result = askName + ", you are " + randOne + " and " + randTwo + "!";
} else if (numOfInsults === "3") {
result = askName + ", you are a " + randOne + ", " + randTwo + " " + randThree + "!";
}
console.log(result);
document.getElementsByTagName('h1')[0].innerHTML = result;
}

generateInsult();


11 changes: 11 additions & 0 deletions challenges/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
h1 {
color: red;
font-family: arial;
text-align: center;
border: 10px solid powderblue;
padding: 40px;
letter-spacing: 1px;
font-weight: 400;
font-size: 40px;
margin: 50px 50px;
}