Skip to content
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 the assignment Homework 2 - Michael Robinson #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thetripler
Copy link

Good assignment

Comment on lines +34 to +95
const cards = [19,20,21,22]

for (i = 0; i < 10; i++) {

const playerCardScore = cards[Math.floor(Math.random() * cards.length)]
const dealerCardScore = cards[Math.floor(Math.random() * cards.length)]

blackJack(playerCardScore,dealerCardScore)

function blackJack(playerCardScore,dealerCardScore) {

if (playerCardScore === 22 && dealerCardScore === 22 ) {

console.log(`Player:${playerCardScore}`)
console.log(`Dealer:${dealerCardScore}`)
console.log('Both 22: 0')
}

else if (playerCardScore === 21 && dealerCardScore === 21 ) {

console.log(`Player: ${playerCardScore}`)
console.log(`Dealer: ${dealerCardScore}`)
console.log('Both 21: 21')
}

if (playerCardScore === 22 || dealerCardScore === 22 ) {

//console.log('One is over 21')
console.log(`Player: ${playerCardScore}`)
console.log(`Dealer: ${dealerCardScore}`)

if (playerCardScore === 22 && dealerCardScore !== 22 ) {

console.log(`Dealer wins with: ${dealerCardScore}`)
}

if (playerCardScore !==22 && dealerCardScore === 22 ) {

console.log(`Player wins with:${playerCardScore}`)

}
}


else if (playerCardScore > dealerCardScore) {

console.log(`Player:${playerCardScore}`)
console.log(`Dealer:${dealerCardScore}`)
console.log(`Player wins with:${playerCardScore}`)

}

else if (playerCardScore < dealerCardScore) {

console.log(`Player:${playerCardScore}`)
console.log(`Dealer:${dealerCardScore}`)
console.log(`Dealer wins with: ${dealerCardScore}`)

}
console.log(`-------------------`)
}
}
Copy link

@Tech-J Tech-J Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thetripler Great work here on the solution here. I see you created a function here to play the game and you have it looping so you can play multiple games. Good use of the array of cards values so you can get a random value to use as your parameters in your blackJack function call.
Take a look at this solution here

Comment on lines +59 to +76
if (playerCardScore === 22 || dealerCardScore === 22 ) {

//console.log('One is over 21')
console.log(`Player: ${playerCardScore}`)
console.log(`Dealer: ${dealerCardScore}`)

if (playerCardScore === 22 && dealerCardScore !== 22 ) {

console.log(`Dealer wins with: ${dealerCardScore}`)
}

if (playerCardScore !==22 && dealerCardScore === 22 ) {

console.log(`Player wins with:${playerCardScore}`)

}
}

Copy link

@Tech-J Tech-J Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thetripler One suggestion I see here you have nested conditionals. this is something you want to avoid if you can. The code works which is good but see if you can rework the conditional so it's not nested.
Take a look at this solution here

Comment on lines +159 to 180
var input = "olly olly in come free";
var arrayOfWords = input.split(/\s+/);

var wordCounts = Object.create(null);

for (i = 0; i < arrayOfWords.length; i++) {
var word = arrayOfWords[i];
// add count of one if new word
if (!wordCounts[word]) {
wordCounts[word] = 1;
} else {
//add if existing
wordCounts[word]++;
}
}

var result = Object.keys(wordCounts).map(function(word) {
console.log(`${word} : ${wordCounts[word]}`)
});


// Add your code above this line
Copy link

@Tech-J Tech-J Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thetripler Good job here and this problem. Your looping through each word and incrementing by 1 if the word exists and setting the value to 1 if the word doesn't exist. I have a suggestion to avoid using the var keyword for creating variables and instead you can use let or const for creating variables. Also for the wordCounts variable instead of using Object.create you can just use an empty object {}.

Take a look at this solution here

Comment on lines +226 to +280
const wordPlayed = "javascript"

scrabbleScore(wordPlayed)

function scrabbleScore(word) {

let sum = 0

const Score1 = ["a","e","i","o","u","l","n","r","s","t"]
const Score2 = ["d","g"]
const Score3 = ["b","c","m","p"]
const Score4 = ["f","h","v","w","y"]
const Score5 = ["k"]
const Score8 = ["j","x"]
const Score10 = ["q","z"]

for (var position = 0; position < word.length; position++) {

let character = word.charAt(position)
//console.log(`character = ${word.charAt(position)}`)

if ( Score1.includes(character)) {
sum = sum + 1
}

else if ( Score1.includes(character)) {
sum = sum + 1
}

else if ( Score2.includes(character)) {
sum = sum + 2
}

else if ( Score3.includes(character)) {
sum = sum + 3
}
else if ( Score4.includes(character)) {
sum = sum + 4
}
else if ( Score5.includes(character)) {
sum = sum + 5
}
else if ( Score8.includes(character)) {
sum = sum + 8
}
else if ( Score10.includes(character)) {
sum = sum + 10
}

}

console.log(`"${word}" has a Scrabble Score of ${sum}`)

}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thetripler Good job here working through this problem. Good job using the function to check each character in the string and increment by the value of the letter. Good job using the array and the includes method to check each letter against the score array.
take a look at an alternate approach here

Comment on lines +321 to +339
const wordToTest = "racecar"

isPalindrome(wordToTest)

function isPalindrome(word) {

const arrayForward = word.split('')
const arrayReverse = word.split('').reverse()

if (arrayForward.toString() === arrayReverse.toString()) {

console.log(`${word} isPalindrome = true`)
}
else {

console.log(`${word} isPalindrome = false`)

}
}
Copy link

@Tech-J Tech-J Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thetripler Good work here coming up with this solution. I see you're splitting and reversing and comparing the reversed string with the current string. One suggestion since you want to compare the word with the reverse of it you don't have to split the word. arrayReverse there is a method that would allow you to turn an array into a string and that's called join. Also for returning true or false you can write the following return false or return true the console.log shows the message but you would want to write your return of true and false like that.

Take a look at a solution here

Comment on lines +399 to +417
const wordTest = "loop"

hasDoubleLetters(wordTest)

function hasDoubleLetters(word) {

let hasDoubles = false

for (var i = 0; i < word.length; i++) {
// console.log(word.charAt(i))
if (word.charAt(i) === word.charAt(i+1)) {
hasDoubles = true
}

}
console.log(`${wordTest} has double letters = ${hasDoubles}`)

}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thetripler Good job here with this solution you have. I see your looping through each letter of the word checking it with the next consecutive letter to verify if they are doubles.
Take a look at this approach here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants