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

homework done #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 148 additions & 1 deletion pset-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Comment on lines +33 to +51
Copy link

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


// Add your code above this line

Expand Down Expand Up @@ -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
Copy link

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





// Add your code above this line

/** added for formatting purposes **/
Expand Down Expand Up @@ -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
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.

@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


// Add your code above this line

Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

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

@jl1982 Great work here with this solution. Nice job using method chaining to reverse the string and to compare that with the original string. One suggestion when you call the function with the variable pal as a parameter.
Take a look at this solution here

// Add your code above this line

/** added for formatting purposes **/
Expand Down Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

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

@jl1982 Good work here on this solution. I see your output is correct and you're getting the right outcome.
Take a look at this solution here


// Add your code above this line

/** added for formatting purposes **/
Expand Down