-
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 done #2
base: master
Are you sure you want to change the base?
Conversation
function blackJack (){ | ||
if(playerCardScore > dealerCardScore && playerCardScore <= 21){ | ||
return `Player wins with a score of ${playerCardScore}` | ||
} | ||
else if(dealerCardScore > playerCardScore && dealerCardScore <= 21) { | ||
return `The dealer wins with a score of ${dealerCardScore}` | ||
} | ||
else { | ||
return `Bust! Player loses with a score of ${playerCardScore}, and the dealer loses with a score of ${dealerCardScore}` | ||
} | ||
|
||
} | ||
|
||
const playerCardScore = 22 | ||
const dealerCardScore = 22 | ||
|
||
|
||
console.log(blackJack()) | ||
|
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.
@nice Job with this solution here. Your blackJack
function looks really good, I see you're utilizing conditionals to do your checks to see what is the outcome of the game. One suggestion when you call the function you would want to pass the variables playerCardScore
and dealerCardScore
as parameters like this blackjack(playerCardScore,dealerCardScore)
then your main function would look like this ex. function blackJack(variable1,variable2)
.
take a look at this solution here
var texts = ["loop", "rune", "apple"]; | ||
|
||
|
||
for(var idx in texts){ | ||
var text = texts[idx].split(""); | ||
console.log(text.join("") + " is " + text.some(function(v,i,a){return a.lastIndexOf(v)!=i;})); | ||
|
||
} |
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 4:') | ||
|
||
// Add your code below this line | ||
|
||
function isPalindrome(){ | ||
|
||
let palRev = pal.split("").reverse().join(""); | ||
|
||
if(pal === palRev){ | ||
console.log(`${pal} is a palindrome!`) | ||
} else{ | ||
console.log(`${pal} is NOT a palindrome!`) | ||
} | ||
} | ||
let pal = "noosh" | ||
isPalindrome() |
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.
let phrase = "Humpty Dumpty sat on a wall Humpty Dumpty had a great fall" | ||
|
||
function wordCount(){ | ||
return phrase.split(" ") | ||
} | ||
|
||
// Was playing with the stuff above but ran into issues figuring out how to solve, below is form googling | ||
|
||
|
||
function compressArray(original) { | ||
|
||
var compressed = []; | ||
// make a copy of the input array | ||
var copy = original.slice(0); | ||
|
||
// first loop goes over every element | ||
for (var i = 0; i < original.length; i++) { | ||
|
||
var myCount = 0; | ||
// loop over every element in the copy and see if it's the same | ||
for (var w = 0; w < copy.length; w++) { | ||
if (original[i] == copy[w]) { | ||
// increase amount of times duplicate is found | ||
myCount++; | ||
// sets item to undefined | ||
delete copy[w]; | ||
} | ||
} | ||
|
||
if (myCount > 0) { | ||
var a = new Object(); | ||
a.value = original[i]; | ||
a.count = myCount; | ||
compressed.push(a); | ||
} | ||
} | ||
|
||
return compressed; | ||
}; | ||
|
||
// It should go something like this: | ||
|
||
var newArray = compressArray(wordCount()); | ||
|
||
console.log(newArray) | ||
|
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.
@jl1982 Good start to the problem with that function returning the word split is a good helper function for your solution. I see you're getting the outcome of an object, but it's not how the hw output should be. If you get some time, revisit the problem and see if you can take another shot at it.
Take a look at this solution here
console.log('Problem 3:') | ||
|
||
// Add your code below this line | ||
let word = "cabbage" | ||
let totalScore = 0 | ||
let score = 0 | ||
//let onePoint = ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T" ] | ||
|
||
function scrabbleScore(){ | ||
return word.split("") | ||
} | ||
|
||
console.log(scrabbleScore()) | ||
|
||
for (let i = 0; i < word.length; i++) { | ||
|
||
//A, E, I, O, U, L, N, R, S, T 1 | ||
if(scrabbleScore()[i] === "a" || scrabbleScore()[i] === "e" || scrabbleScore()[i] === "i" || scrabbleScore()[i] === "o" || scrabbleScore()[i] === "u" || | ||
scrabbleScore()[i] === "l" || scrabbleScore()[i] === "n" || scrabbleScore()[i] === "r" || scrabbleScore()[i] === "s" || scrabbleScore()[i] === "t") { | ||
score++ | ||
} | ||
//D, G 2 | ||
else if (scrabbleScore()[i] === "d" || scrabbleScore()[i] === "g") { | ||
score += 2 | ||
} | ||
//B, C, M, P 3 | ||
else if (scrabbleScore()[i] === "b" || scrabbleScore()[i] === "c" || scrabbleScore()[i] === "m" || scrabbleScore()[i] === "p") { | ||
score += 3 | ||
} | ||
//F, H, V, W, Y 4 | ||
else if (scrabbleScore()[i] === "f" || scrabbleScore()[i] === "h" || scrabbleScore()[i] === "v" || scrabbleScore()[i] === "n" || scrabbleScore()[i] === "y") { | ||
score += 4 | ||
} | ||
//K 5 | ||
else if (scrabbleScore()[i] === "k"){ | ||
score += 5 | ||
} | ||
//J, X 8 | ||
else if (scrabbleScore()[i] === "j" || scrabbleScore()[i] === "x") { | ||
score += 8 | ||
} | ||
//Q, Z 10 | ||
else if (scrabbleScore()[i] === "Q" || scrabbleScore()[i] === "Z") { | ||
score += 10 | ||
} | ||
|
||
} | ||
|
||
console.log(score) | ||
|
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.
@jl1982 Good Job on this problem here. Looping through each letter as you split the word into an array. Good job with your conditionals to check for each letter and increment the value of score
by the point for the letter. One suggestion for line 257 you should keep the string ex. q and z should be lowercase. Since all of the other letter is lowercase you would want to keep them all consistent.
Take a look at this solution here
Homework Completed