-
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?
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,6 +30,25 @@ 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 (){ | ||
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()) | ||
|
||
|
||
// Add your code above this line | ||
|
||
|
@@ -91,6 +110,67 @@ console.log('Problem 2:') | |
|
||
// Add your code below this line | ||
|
||
/* | ||
//testing out split array | ||
console.log(wordCount()[1]) | ||
|
||
//testing out calling each array | ||
wordCount().forEach(function(element, index) { | ||
console.log(`${element} is at index ${index}`) | ||
}) | ||
|
||
//*/ | ||
|
||
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) | ||
|
||
Comment on lines
+124
to
+169
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. @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 |
||
|
||
|
||
|
||
|
||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -135,6 +215,53 @@ Use the following test cases to confirm your program meets the success criteria | |
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) | ||
|
||
Comment on lines
215
to
+264
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. @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 Take a look at this solution here |
||
|
||
// Add your code above this line | ||
|
||
|
@@ -174,7 +301,18 @@ 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(){ | ||
|
||
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() | ||
Comment on lines
301
to
+315
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 +346,15 @@ console.log('Problem 5:') | |
|
||
// Add your code below this line | ||
|
||
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;})); | ||
|
||
} | ||
Comment on lines
+349
to
+356
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.
@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 variablesplayerCardScore
anddealerCardScore
as parameters like thisblackjack(playerCardScore,dealerCardScore)
then your main function would look like this ex.function blackJack(variable1,variable2)
.take a look at this solution here