-
Notifications
You must be signed in to change notification settings - Fork 29
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
Eva-Liisa JS Basic problem Set #18
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,17 @@ | |
*/ | ||
|
||
// YOUR CODE HERE | ||
|
||
function isPalindrome(str) { | ||
var newStr = str.replace(/[^\w\s]/gi, '').replace(/ /g,'').toLowerCase(); //remove punctuation and spaces, convert to lowercas | ||
let revString = "" | ||
for (var i = newStr.length - 1; i >= 0; i-= 1 ) { | ||
revString += newStr[i]; | ||
} | ||
|
||
if (revString == newStr) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this works, you could replace lines 32-36 with just |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,30 @@ | |
*/ | ||
|
||
// YOUR CODE HERE | ||
function isPrime(num) { | ||
if (num < 2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you for correctly handling the fact that 1 is not prime! 😁 |
||
return false | ||
} else { | ||
for (var i = 2; i < num; i++) { | ||
if (num % i === 0) { | ||
return false | ||
} | ||
} | ||
return true | ||
}; | ||
}; | ||
|
||
function prime(max) { | ||
var primeArr = []; | ||
var number = 2; | ||
|
||
while (primeArr.length < max) { //loop runs until the length of the array of prime number is equal to max | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Watch your indentation here--it'll be easier to debug your code if it's easier to read. |
||
|
||
let isItAPrime = isPrime(number); | ||
if (isItAPrime) { | ||
primeArr.push(number); | ||
} | ||
number += 1; | ||
} | ||
return primeArr | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,27 @@ | |
- Create a browser interface, using some combination of `prompt`, `alert`, and/or DOM manipulation. | ||
|
||
*/ | ||
// YOUR CODE HERE | ||
|
||
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 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"]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this curly brace? Where did it come from??? |
||
|
||
// YOUR CODE HERE | ||
function generateRandom(currentArr) { //passes the current array through the function and generates a random word from that array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of functions to do this repeated functionality. |
||
var word = currentArr[Math.floor(Math.random() * currentArr.length)] | ||
return word; | ||
} | ||
|
||
function generateInsult (numOfWords) { | ||
var selectedInsults = ["Why you, "] | ||
var wordArray = [first_word, second_word, third_word] | ||
|
||
for (var i = 0; i < wordArray.length; i++) { | ||
var currentInsult = generateRandom(wordArray[i]); | ||
selectedInsults.push(currentInsult); | ||
} | ||
|
||
return selectedInsults.join(" ") | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this is good use of Googling, but even so, I'm glad you were able to get this working!