-
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
completed hw #10
base: master
Are you sure you want to change the base?
completed hw #10
Conversation
function doubleLetters (word) { | ||
const wordLetters = word.split('') | ||
let hasDoubleLetters = false | ||
|
||
// iterate through letters of the submitted word | ||
wordLetters.forEach((letter, index) => { | ||
// declare the current letter and previous letter of the iteration | ||
const currentLetter = wordLetters[index] | ||
const previousLetter = wordLetters[index - 1] | ||
|
||
// debug | ||
// console.log(`current letter is ${currentLetter}. previous letter was ${previousLetter}.`) | ||
|
||
// if they're the same, then double letters are present, | ||
// return true | ||
if (currentLetter === previousLetter) { | ||
hasDoubleLetters = true | ||
} | ||
}) | ||
|
||
return (hasDoubleLetters) | ||
} | ||
|
||
console.log(doubleLetters('apple')) |
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) { | ||
if (word === reverseWord(word)) { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
function reverseWord (fwd) { | ||
const str = fwd.split('') | ||
const reverseStr = str.reverse() | ||
const reversedWord = reverseStr.join('') | ||
|
||
return reversedWord | ||
} | ||
|
||
console.log(isPalindrome('run')) |
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.
const pointChart = [ | ||
{ letters: 'aeioulnrst', points: 1 }, | ||
{ letters: 'dg', points: 2 }, | ||
{ letters: 'bcmp', points: 3 }, | ||
{ letters: 'fhvwy', points: 4 }, | ||
{ letters: 'k', points: 5 }, | ||
{ letters: 'jx', points: 8 }, | ||
{ letters: 'qz', points: 10 } | ||
] | ||
|
||
function scrabbleScore (word) { | ||
const lettersInWord = word.split('') | ||
let wordScore = 0 | ||
|
||
// iterate over the letters in the submitted word | ||
lettersInWord.forEach(function (letter) { | ||
// interate over the points array and find which letter | ||
// is currently selected | ||
pointChart.forEach((value) => { | ||
// debug | ||
// console.log(value['letters']) | ||
|
||
// create an array of letters that align the current | ||
// amount of points to be given. these letters will be compared | ||
// against the current letter in the word that was submitted | ||
const comparisonLetters = value.letters.split('') | ||
|
||
// debug | ||
// console.log(comparisonLetters) | ||
|
||
// find if the current letter from the submitted word exists | ||
// within the set of letters for this point value. | ||
// if it does, add points. if not, the set the loop proceeds | ||
// to the next set of letters associated with value['points'] | ||
if (comparisonLetters.find(element => element === letter)) { | ||
wordScore += (value.points) | ||
|
||
// debug | ||
// console.log(`new wordScore is ${wordScore}`) | ||
} | ||
}) | ||
}) | ||
|
||
return (`This word is worth ${wordScore} points`) | ||
} | ||
|
||
console.log(scrabbleScore('function')) |
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 words = phrase.split(' ') | ||
// empty array for counting words | ||
const wordCounter = {} | ||
|
||
// for each word in the phrase | ||
words.forEach((word) => { | ||
if (wordCounter[word] === undefined) { | ||
// debug | ||
// console.log ('word doesnt exist. adding word') | ||
wordCounter[word] = 1 | ||
} else { | ||
wordCounter[word] = wordCounter[word] + 1 | ||
} | ||
}) | ||
|
||
return wordCounter | ||
} | ||
|
||
console.log(wordCount('Humpty Dumpty sat on a wall Humpty Dumpty had a great fall')) | ||
// Add your code above this line |
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 blackJack (playerCardScore, dealerCardScore) { | ||
// first, let's determine if there are any entries above 21 | ||
if ((playerCardScore > 21) && (dealerCardScore > 21)) { | ||
return 0 | ||
} else if (playerCardScore > 21) { | ||
return dealerCardScore | ||
} else if (dealerCardScore > 21) { | ||
return playerCardScore | ||
} else { | ||
// if none of the entries are above 21 the score will be calculated | ||
calculateScore(playerCardScore, dealerCardScore) | ||
} | ||
} | ||
|
||
function calculateScore (player, dealer) { | ||
// calculate the difference from 21 for each score | ||
const playerScore = 21 - player | ||
const dealerScore = 21 - dealer | ||
|
||
// if playerScore has a larger difference from 21 then return dealerScore | ||
if (playerScore > dealerScore) { | ||
return dealerScore | ||
} else { | ||
return playerScore | ||
} | ||
} | ||
|
||
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.
@sad3xoxo Good work here on this problem I see you have your blackjack function checking to see the player's values and you have the calculate score to return the score.
For calculateScore(playerCardScore, dealerCardScore)
since that function is returning a value you need to include the keyword return
. the return
will allow you to get the value from the calculateScore
function and display is you when you console.log(blackJack(19, 22))
on line 60.
One suggestion for your calculateScore
function currently you're returning the playerScore/dealerScore
after you have subtracted 21 - player/dealer
. You could return the player or dealer value in the conditional statement.
Take a look at this solution here
yay