Assignment 2 scoringAlgorithm/scorerPrompt

I’m now stuck on the transform function. I understand what it is asking of us, but I can’t figure out where to begin other than starting with this:

function transform(oldPointStructure) {
for (items in oldPointStructure) {

}
};

1 Like

that’s what I’m working on currently lol

Well, if you get to a point where you’re confident you know what you’re doing let me know as I am at a roadblock with this code block lol

EDIT: This is what I have right now, but I can’t figure out how to get rid of the original object array. Don’t know if I need to sort them either.

1 Like

I would negate that, found a much better way to do it. I created an object in transform to hold the data abd returned it instead.

1 Like

If you made the functions anonymous, that is let scrabbleScore = function(){}, then in the object block you can leave the () off of the function name.

I did that earlier, but it kept giving me this when I put in apple as the word

In order for your function to properly return something you need to give it an argument it’ll use through its code block. word is only a placeholder (unless you defined it yourself). Here in order for any of your scoring algos to work you have to pass them the variable name matching the user’s original word input - which for your code seems to be initialWord.

I did define word myself in each of the different score functions. Only the first two functions actually give me a total score while the scrabbleScore function lists the scores of each numbers (including a 0 to start the chain). So I’m kind of lost as I know my newPointStructure object array is working as it should. It’s just my scrabbleScore function. I’m wondering if I need to add another loop inside the For loop I already have:

let scrabbleScore = function(word){
word = word.toLowerCase();
let points = 0;

for (let i = 0; i < word.length; i++) {
letter = newPointStructure[word[i]];
points += letter[0];
}
return points;
};

Since newPointStructure is an object (transformation of oldPointStructure object) I used a for/in loop to iterate through it & then be able to += its property values every time there was a match. There may be a better way but I couldn’t find it.

I’m at a loss, I added a for in loop but it still isn’t summing the point values of the letters together.

@SprintsMcGee In your scrabbleScore function, it looks to me like your points.typeOf is probably string. It is attempting to “add” the values by stringing them together next to each other instead of actually adding them. You could try points.toString within the function and see if that helps!

I did indeed see that earlier, so I changed my transform function to output numbers instead of strings at each of the keys. Now it’s returning a single number, but it’s only returning a 0 so nothing is actually happening in my scrabbleScore function except points returning a 0.

EDIT: I have it setup like this: let scrabbleScore = function(word){
word = word.toLowerCase();
let points = 0;

for (l in newPointStructure) {
for (let i = 0; i < word.length; i++) {
if (newPointStructure[l] == word[i]) {
points += l[0];
}
}
}

return points;
};

Hmm. Did you try to console.log print your newPointStructure to ensure that the letters are all indeed lowercase? I got it to work looking closer to your original screencap, without the for… in loop.
image

1 Like

I did…and what you just showed me fixed everything. I don’t understand why I’m iterating over the newPointStructure object anymore though.

Good find Cedric, that worked perfectly. Though I don’t quite understand why it is required. I’ll reread the functions sections and see if it makes more sense afterwards.On to the next issue.

I hope everyone is having better luck than I am. I actually have been having a really tough time understanding the general idea of what it is that we are doing. I get that we are transforming the function into a different form of iteration but I am very confused on how the logic works. The assignment said we were able to complete it after week 3 but the whole assignment works around objects from week 4. I managed to get the same result as SprintsMcGee, with the array printing above the actual keys. I understand how you made each letter equal to the value but I am confused on how to get rid of the array above and how you managed to find a new data point to implement it.

Hey Miclamb, did you get anywhere? I have tried multiple iterations of the transformation structure, and am continuously receiving errors regarding an issue in my oldScrabbleScorer function. I don’t even remember at this point if oldScrabbleScorer was given, but it certainly seems odd that it is having an issue now.
SS below for reference.


image
image

I have not managed to get the iterations to work. I am actually confused on how to make new keys for the values. Right now I am testing my transform function to make sure the object is being passed. Once I manage to get the iterations of the keys, I will be back to let you know what I have done.

Thanks. I just reviewed Terrance’s message on slack (javascript-helpful-videos), and I’m mulling it over; but unfortunately I haven’t experienced any major breakthroughs yet.

Where did you find the videos at? I had no clue videos were available.