-
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
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 |
---|---|---|
|
@@ -30,7 +30,34 @@ Use the following test cases to confirm your program meets the success criteria | |
console.log('Problem 1:') | ||
|
||
// Add your code below this line | ||
|
||
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)) | ||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -91,6 +118,26 @@ console.log('Problem 2:') | |
|
||
// Add your code below this line | ||
|
||
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 | ||
Comment on lines
+121
to
141
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. |
||
|
||
/** added for formatting purposes **/ | ||
|
@@ -136,6 +183,53 @@ console.log('Problem 3:') | |
|
||
// Add your code below this line | ||
|
||
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')) | ||
Comment on lines
+186
to
+232
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. |
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -174,7 +268,23 @@ Use the following test cases to confirm your program meets the success criteria | |
console.log('Problem 4:') | ||
|
||
// Add your code below this line | ||
|
||
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')) | ||
Comment on lines
+271
to
+287
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. |
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -208,6 +318,30 @@ console.log('Problem 5:') | |
|
||
// Add your code below this line | ||
|
||
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')) | ||
Comment on lines
+321
to
+344
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. |
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
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 keywordreturn
. thereturn
will allow you to get the value from thecalculateScore
function and display is you when youconsole.log(blackJack(19, 22))
on line 60.One suggestion for your
calculateScore
function currently you're returning theplayerScore/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