-
Notifications
You must be signed in to change notification settings - Fork 12
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
Homework 2- Natalie Mikhol #7
base: master
Are you sure you want to change the base?
Conversation
function blackJack(playerCardScore, dealerCardScore ){ | ||
|
||
if(playerCardScore > 21 && dealerCardScore > 21){ | ||
return 0 | ||
} else if (playerCardScore > dealerCardScore && playerCardScore <= 21 || dealerCardScore > 21){ | ||
return playerCardScore | ||
} else { | ||
return dealerCardScore | ||
} | ||
} | ||
|
||
console.log(blackJack(19, 22)) | ||
|
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.
function wordCount(phrase){ | ||
const cleanedPhrase = phrase.replace(/[,.]/g, '') | ||
const splitWords = cleanedPhrase.split(' ') | ||
const wordCount = {} | ||
|
||
splitWords.forEach((splitWord) => { | ||
if(wordCount[splitWord] === undefined) { | ||
wordCount[splitWord] = 1 | ||
} else { | ||
wordCount[splitWord] += 1 | ||
} | ||
}) | ||
return wordCount | ||
|
||
} | ||
|
||
console.log(wordCount("Baby shark, doo doo doo doo doo doo")) |
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.
console.log('Problem 3:') | ||
|
||
// Add your code below this line | ||
function scrabbleScore(word){ | ||
const splitLetters = word.split("") | ||
let sum = 0 | ||
const points = { | ||
a: 1, | ||
b: 3, | ||
c: 3, | ||
d: 2, | ||
e: 1, | ||
f: 4, | ||
g: 2, | ||
h: 4, | ||
i: 1, | ||
j: 8, | ||
k: 5, | ||
l: 1, | ||
m: 3, | ||
n: 1, | ||
o: 1, | ||
p: 3, | ||
q: 10, | ||
r: 1, | ||
s: 1, | ||
t: 1, | ||
u: 1, | ||
v: 4, | ||
w: 4, | ||
x: 8, | ||
y: 4, | ||
z: 10 | ||
} | ||
|
||
splitLetters.forEach((splitLetter) => { | ||
sum += points[splitLetter] | ||
}) | ||
|
||
return sum | ||
} | ||
|
||
console.log(scrabbleScore("javascript")) |
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.
function isPalindrome(word){ | ||
let splitWords = word.split('') | ||
let reversedArr = splitWords.reverse() | ||
let reversedWord = reversedArr.join("") | ||
if(word === reversedWord){ | ||
return true | ||
} else{ | ||
return false | ||
} | ||
} | ||
|
||
console.log(isPalindrome("noon")) |
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.
function doubleLetters(word){ | ||
let letters = word.split('') | ||
let result = false | ||
letters.forEach((letter, index) => { | ||
if (letter === letters[index+1]){ | ||
result = true | ||
} | ||
}) | ||
return result | ||
} | ||
|
||
console.log(doubleLetters("rune")) |
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.
@nmikhol Good job on this problem here. I see you split the word into an array and your looping through each element checking to see the current and next letter match, Good job on that. One suggestion instead of creating the variable result and changing it to true of false, Since your using a boolean you can return true and return result explicitly instead of changing it through a variable. since your looking for the consecutive letter in a word once you find the consecutive repeating word if you return true that would stop the program since you arrived at an answer.
Take a look at an alternate solution here
Having trouble with problem 5