Skip to content

Javascript Basics Problem Set #13

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

Open
wants to merge 7 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
9 changes: 9 additions & 0 deletions challenges/bottles-of-beer-song.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@
*/

// YOUR CODE HERE
function beerBottles() {
for (i = 5; i > 0; i--) {
var less = i - 1;
console.log(i + ' bottles of beer on the wall,');
console.log(i + ' bottles of beer!');
console.log('Take one down and pass it around,');
console.log(less + ' bottles of beer on the wall...');
}
}
7 changes: 7 additions & 0 deletions challenges/palindrome-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@
*/

// YOUR CODE HERE
function isPalindrome(input) {
var lowerCase = input.toLowerCase();
var noPunctuation = lowerCase.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"");
var noSpace = noPunctuation.replace(/\s+/g, '');
var output = noSpace.split("").reverse().join("");
return noSpace === output;
}
23 changes: 23 additions & 0 deletions challenges/primes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,26 @@
*/

// YOUR CODE HERE

//part 1
function isPrime(num) {
if (num < 2) return false;
if (num == 2) return true;
for (var i = 2; i < Math.sqrt(num)+1; i++) {
if (num % i === 0) {
return false;
}
}
return true;
}

//part 2
function primes(max) {
var output = [];
for (var i = 2; i <= max; i++)
if (isPrime(i)) {
output.push(i);
}
return output;

}
26 changes: 26 additions & 0 deletions challenges/shakespearian-insult-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,29 @@ 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

//Insult Generator
var first = Math.floor(Math.random() * (first_word.length - 1));
var second = Math.floor(Math.random() * (second_word.length - 1));
var third = Math.floor(Math.random() * (third_word.length - 1));

function insultGenerator() {
return 'You ' + first_word[first] + second_word[second] + third_word[third] + ' you!';
}


//Bonuses
var all_words = first_word.concat(second_word, third_word);

function generateInsult() {
var randomNumber = Math.floor(Math.random() * (all_words.length - 1));
return all_words[randomNumber];
}

function generateInsults(num) {
var output = [];
for (i = 0; i < num; i++) {
output.push(generateInsult());
}
return output;
}