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

Homework 2- Natalie Mikhol #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

nmikhol
Copy link

@nmikhol nmikhol commented Sep 25, 2019

Having trouble with problem 5

Comment on lines +34 to +46
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))

Copy link

Choose a reason for hiding this comment

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

@nmikhol Good Job here creating this function to check for the different outcomes to determine the winner in the game. Good job using that && operator to check the two conditions in that statement.
take a look at a solution here

Comment on lines +107 to +123
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"))
Copy link

Choose a reason for hiding this comment

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

@nmikhol Nice work here creating a function that checks the splits the string into an array and loop over those elements to either set to 1 if the word doesn't exist or increment by 1 if it does.
Take a look at this solution here

Comment on lines 166 to +208
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"))
Copy link

Choose a reason for hiding this comment

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

@nmikhol Awesome work here creating an object with all the letters and values for each one. Then looping each element and adding the sum by accessing the value in the points object, based on each letter.
Take a look at this solution here

Comment on lines +249 to +260
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"))
Copy link

@Tech-J Tech-J Oct 10, 2019

Choose a reason for hiding this comment

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

@nmikhol Good work her on this solution

  • taking the string and splitting into an array
  • reversing the string and joining to convert back to a string
  • and checking against the original word to return true if it's a palindrome and false if it's not.

Take a look at this solution here

Comment on lines +312 to +323
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"))
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants