Skip to content

Finished problem set #19

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

// YOUR CODE HERE
var x = 5;

while (x >= 1) {
var y = x-1;
console.log (
x + " bottles of beer on the wall, \n" +
x + " bottles of beer!\n" +
"Take one down and pass it around,\n" +
y + " bottles of beer on the wall...\n\n "
)
x = x-1
}

BONUS

var x = 5;

while (x >= 1) {
var y = x-1;

if (x==2) {
console.log (
x + " bottles of beer on the wall, \n" +
x + " bottles of beer!\n" +
"Take one down and pass it around,\n" +
y + " bottle of beer on the wall...\n\n "
)}

else if(x==1) {
console.log(
x + " bottle of beer on the wall, \n" +
x + " bottle of beer!\n" +
"Take one down and pass it around,\n" +
"No more bottles of beer on the wall...\n\n "
)}

else {
console.log (
x + " bottles of beer on the wall, \n" +
x + " bottles of beer!\n" +
"Take one down and pass it around,\n" +
y + " bottles of beer on the wall...\n\n "
)}
x = x-1;
};
80 changes: 80 additions & 0 deletions challenges/palindrome-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,83 @@
*/

// YOUR CODE HERE
/* I googled "how do I fetch last letter in a string, which brought me to this page
http://stackoverflow.com/questions/3884632/how-to-get-the-last-character-of-a-string
and from there it sparked some leads as to how I should proceed*/


NEW AND UPDATED (THE WORD INPUTED MUST HAVE NO SPACES OR PUNCTUATION. FURTHERMORE,
THE SEQUENCE OF UPPERCASE/LOWERCASE MUST MATCH FROM BOTH DIRECTIONS)

function isPalindrome(word){
var theword= word;
var thelastletterindex=theword.length-1;
var divisibility=theword.length % 2;
var midpoint=0;
var palicheck=0;
if (divisibility===0){
midpoint=theword.length/2;
}
else{
var adjustlength=theword.length-1;
midpoint=adjustlength/2;
}

for (n=0;n<midpoint; n++){

if (theword.charAt(0+n)===theword.charAt(thelastletterindex-n)){

}
else{
palicheck=5;
}
}

if (palicheck===5){
console.log("It is not a palindrome");
return false;
}
else{
console.log("Yes! Congrats, you've caught a palindrome");
return true;

}

}


OLD CODE: (DOES NOT WORK..HERE ONLY FOR REFERENCE.)


function isPalindrome(word){
var theword= word;
var lastletterindex=theword.length-1;
var divisibility=theword.length % 2;
var midpoint=0;
var palicheck=0;
if (divisibility=0){
midpoint=theword.length/2;
}
else{
var adjustlength=theword.length-1;
midpoint=adjustlength/2;
}

for (n=0;n<midpoint; n++){

if (theword.charAt(0+n)===theword.charAt(thelastletterindex-n){

}
else{
palicheck=5;
}
if (palicheck=5){
console.log("It is not a palindrome");
return false;
}
else{
console.log("Yes! Congrats, you've caught a palindrome");
return true;

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

// YOUR CODE HERE


function isPrime(number) {
var primeness=0;
for (i=2; i<number; i++){
factortest = number % i;
if (factortest==0){
primeness=1;
}

}
if (primeness==1){
console.log("This number is not prime!")
}
else {
console.log("Congrats ma'am THIS NUMBER IS PRIME!")
}

}

Problem 2

var array =[];

function isPrime(number) {
var primeness=0;
for (i=2; i<number; i++){
factortest = number % i;
if (factortest==0){
primeness=1;
}

}
if (primeness==1){
return false;
}
else {
return true;
}

}


function primes(max) {

for (i=1; i<=max; i++){
if (isPrime(i)){
array.push(i);
}
}

};
55 changes: 54 additions & 1 deletion challenges/shakespearian-insult-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,61 @@

*/

/* At first I put the three "var firstindex=getrandom()" outside the for loops in which
they are used to specify the index number of array to be called, but then I
saw that I was getting the same words from each array throughout!!! So I realized
I had to put the var firstindex=getrandom assignments inside the forloops
so that there is a new index assignment through each run of each array group
in every loop! */

/*for numbers that are not multiples of 3, the last one or two words are only from
the first word array */

var first_word = ["yeasty", "weedy", "wayward", "warped", "villainous", "venomed", "vain", "unmuzzled", "tottering", "surly", "spongy", "spleeny", "saucy", "ruttish", "roguish", "reeky", "rank", "qualling", "puny", "puking", "pribbling", "paunchy", "mewling", "mangled", "mammering", "lumpish", "loggerheaded", "jarring", "infectious", "impertinent", "gorbellied", "goatish", "gleeking", "frothy", "froward", "fobbing", "fawning", "errant", "droning", "dissembling", "dankish", "currish", "craven", "clouted", "cockered", "churlish", "bootless", "beslubbering", "bawdy", "artless"];
var second_word = ["weather-bitten", "unchin-snouted", "toad-spotted", "tickle-brained", "tardy-gaited", "swag-bellied", "spur-galled", "sheep-biting", "shard-borne", "rump-fed", "rude-growing", "rough-hewn", "reeling-ripe", "pox-marked", "pottle-deep", "plume-plucked", "onion-eyed", "motley-minded", "milk-livered", "knotty-pated", "ill-nurtured", "ill-breeding", "idle-headed", "hell-hated", "hedge-born", "hasty-witted", "half-faced", "guts-griping", "full-gorged", "fool-born", "folly-fallen", "fly-bitten", "flap-mouthed", "fen-sucked", "fat-kidneyed", "elf-skinned", "earth-vexing", "dread-bolted", "doghearted", "dizzy-eyed", "dismal-dreaming", "crook-pated", "common-kissing", "clay-brained", "clapper-clawed", "boil-brained", "beetle-headed", "beef-witted", "bat-fowling", "base-court"];
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

function generateInsult(num){
var username = window.prompt("Tell me your name");
var listofinsults=[];
var lastIndexInFirst= first_word.length-1;
var lastIndexInSecond= second_word.length-1;
var lastIndexInThird= third_word.length-1;

function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}



if(num==1){
listofinsults.push(first_word[firstindex]);
}
else if(num==2){
listofinsults.push(first_word[firstindex]);
listofinsults.push(second_word[secondindex]);
}

else if (num>2){
var divided=num/3;
var remainder=num % 3;
var count = Math.floor(divided);
for(i=0; i<count; i++) {
var firstindex= getRandomInt(0,lastIndexInFirst);
var secondindex = getRandomInt(0,lastIndexInSecond);
var thirdindex = getRandomInt(0,lastIndexInThird);
listofinsults.push(first_word[firstindex]);
listofinsults.push(second_word[secondindex]);
listofinsults.push(third_word[thirdindex]);
}
if (remainder >0){
for (i=0;i<remainder; i++) {
var firstindex= getRandomInt(0,lastIndexInFirst);
listofinsults.push(first_word[firstindex]);
}
}
}
console.log("Why " + username +", you " + listofinsults + ".");

}