-
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
Add files via upload #9
base: master
Are you sure you want to change the base?
Conversation
function blackJack(playerCardScore, dealerCardScore) { | ||
|
||
if (playerCardScore>21 && dealerCardScore>21) { | ||
result = 0 | ||
} else if (playerCardScore>21 || dealerCardScore>21) { | ||
result = Math.min(playerCardScore, dealerCardScore) | ||
} | ||
else { | ||
result = Math.max(playerCardScore, dealerCardScore) | ||
} | ||
return result | ||
} | ||
|
||
const a=19 | ||
const b=21 | ||
console.log("Test case a=19 and b=21. Winner is:") | ||
console.log(blackJack(a,b)) | ||
|
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.
@AtleLohrmann Good job here creating a function and utilizing the conditionals to get to your solution. Nice job utilizing the Math library methods max and min it's a nice feature for this use case.
take a look at this alternate solution here
function wordCount(phrase) { | ||
// Have to split the sentence into words | ||
// first get rid of possible commas -- | ||
const nocomma=phrase.replace(',',"") | ||
const words=nocomma.split(" ") | ||
const nWord={} | ||
//loop through the number of words in the sentence and | ||
//check for each of the words we have already identifies | ||
words.forEach((word) => { | ||
// console.log(nWord[word]) | ||
if (nWord[word] === undefined) { | ||
nWord[word] = 1 | ||
} else { | ||
nWord[word]++ | ||
} | ||
}) // closing the loop | ||
return nWord | ||
} // closing the function | ||
|
||
const phrase="Baby shark, doo doo doo doo doo doo" | ||
console.log("Test:" + phrase) | ||
console.log(wordCount(phrase)) |
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.
@AtleLohrmann Nice job her creating this function here to take to create the object with the phrase
and value of each time a word is repeated. Good job on the splitting the string and checking each word to either set to one if it doesn't exist else increment the value by 1.
Take a look at this solution here
function scrabbleScore(word) { | ||
// Have to split the sentence into words | ||
let characters=word.split("") | ||
let points=0 | ||
// put the cases inside arrays to facilitate adding points | ||
const onePoint=["a","e","i","o","u","l","n","r","s","t"] | ||
const twoPoint=["d","g"] | ||
const threePoint=["b","c","m","p"] | ||
const fourPoint=["f","h","v","w","y"] | ||
const fivePoint=["k"] | ||
const eightPoint=["j","x"] | ||
const tenPoint=["q","z"] | ||
//loop through the number of characters in the workd | ||
|
||
for (var i = 0; i < characters.length; i++) { | ||
// check which point categories the character belongs in and add points | ||
if (onePoint.includes(characters[i])) { | ||
points=points+1 | ||
} else if (twoPoint.includes(characters[i])) { | ||
points=points+2 | ||
} else if (threePoint.includes(characters[i])) { | ||
points=points+3 | ||
} else if (fourPoint.includes(characters[i])) { | ||
points=points+4 | ||
} else if (fivePoint.includes(characters[i])) { | ||
points=points+5 | ||
} else if (eightPoint.includes(characters[i])) { | ||
points=points+8 | ||
} else if (tenPoint.includes(characters[i])) { | ||
points=points+10 | ||
}//find in the point categories | ||
} //for each charater in the test word | ||
return points | ||
} // end of function | ||
|
||
const word="function" | ||
console.log("Test: " + word) | ||
console.log("Number of points: " + scrabbleScore(word)) |
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.
@AtleLohrmann Great work here on this problem. good use of the array method includes
to check if each character against the point arrays and add the points up.
Take a look at this solution here
console.log('Problem 4:') | ||
|
||
// Add your code below this line | ||
function isPalindrome(word){ | ||
// split the word into characters | ||
let wordChar=word.split("") | ||
let reverseWord=[] | ||
//console.log(wordChar) | ||
// add the characters into reverseWord in reverseorder | ||
for (let i = 0; i < wordChar.length; i++) { | ||
reverseWord[wordChar.length-i-1]=wordChar[i] | ||
} | ||
// Output the word and the revers for debugging | ||
console.log("Original word: " + word) | ||
console.log("Revers word: " + reverseWord.join("")) | ||
// check if we have a Palindrome | ||
if (word===reverseWord.join("")) { | ||
return true | ||
} | ||
} | ||
|
||
const test="racecar" | ||
if (isPalindrome(test)) | ||
{console.log("is a Palindrome") | ||
} else | ||
{console.log("maybe undefined") | ||
} | ||
|
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.
@AtleLohrmann Good work on this problem. Good job using that isPalindrome
function to compare the word as is and reversed. I see your looping through each character in reverse and adding it to your array reverseWord
. where you split the word into the array wordChar
, there is a method for arrays called reverse()
which would reverse the array for you. It's a good tool and you could check out some information on it here
One suggestion for lines 277 to 281 you could wrap that up in a function and call it.
take a look at this solution here
function doubleLetters(word) { | ||
// Have to split the sentence into words | ||
// first get rid of possible commas -- | ||
const characters=word.split("") | ||
let double=false | ||
//loop through the number of words in the sentence and | ||
//check for each of the words we have already identifies | ||
for (var i = 0; i < (word.length)-1; i++) { | ||
if (characters[i]===characters[i+1]) { | ||
double=true | ||
} | ||
} //closing the todoloop | ||
return double | ||
} // closing the function | ||
|
||
const testword="runu" | ||
console.log("Test: " + testword) | ||
console.log("Result for double character test:", doubleLetters(testword)) | ||
|
||
|
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.
@AtleLohrmann Good work here on this here. Your looping through each letter and comparing it against the next letter, good job coming to that solution. One suggestion since your using the boolean to determine if the consecutive letter exist you could return true
on line 327 and return false
on line 330. the benefit of that is if the letter repeats itself twice when your return true
that stops the program and doesn't continue searching the other letters since you got your answer.
take a look at this solution here
Hi, finally my answer to lesson number 2. Hope this works