Assignment 2 scoringAlgorithm/scorerPrompt

For Assignment 2 I have everything working in the program up to creating the scoringAlgorithms array and scorePrompt function. From my understanding of the directions, the way I have it set gives me this error! :dizzy_face: deleted screenshots - provide a description of your error and code instead! :dizzy_face:

I’ve tried looking up online to see if there was a way to put a function into an object, but I haven’t had any luck with that. I’m not even sure if it’s the array itself or the scorePrompt function that is giving me the error since when I delete all that work the program starts working again from before that part of the assignment. Any advice that’ll put me on the right path would be appreciated.

:raised_hand: removed replit locations :raised_hand:

I am having the exact same issue. I am also unsure of how to put that function into the object. I have tried a few ways and I’m still stuck. Sometimes it doesn’t recognize the variable ‘word’. I think the tip just after B- 3.c. is a hint at how to refer to the array of objects, but I’m still stuck. I also had the if, else if… statements like you before I went back and read that again. If I do figure out how to properly name the functions in the objects I am hoping the second console.log statement in that tip will work. Right now only the first one does. In place of the [0] I have the name of my input question variable for the score type.

I too am having difficulty getting through this portion. Initially I had the issue that the OP shows, however changing a given function’s return value cleared that up (changed from outputting the letters with their corresponding point value to the total point value of the word). Now however, I can see the array is calculating and outputting correctly if I call it in the initialPrompt function; though regardless of how I write scorerPrompt I do not receive the desired output-the program just ends.
The image below displays that the simple scorer (0) has been chosen, and after that, nothing. I’ll update if I figure it out.

I’m sorry you’re having such a frustrating time with this. Here is the answer: when you add the parentheses you are calling the function. Just remove them & you should be good to go. The variable is a typeof function so just referring to it will add it (a function) to your object as a property value.

Your conditional is the issue. Hint - look for strict equality and not variable reassignment. That will clear it up in no time :slight_smile:

1 Like

Thank you. After getting rid of the parenthesis it looks like scorerPrompt() function is now reading through the array. However, instead of using the function I’m trying to call it reads [Function: simpleScorer] when I type 0. I made sure the functions were actually working like they did originally, and tried to pass other arguments into scorerPrompt() to see if that would change anything. The only thing I can think of being wrong are the second statements in each of my if/else loops

Yes I am confirming that your function callouts in scorerPrompt are the issue here. Hint : review the build of each function so you know how to properly call/invoke it.
Additionally there may be some confusions around use of =, == & ===.

1 Like

THANK YOU! That helped me… now on to the next problem😩
I took out all the if, else if statements and I’m trying to refer to the array. If I use (word) it says it is undefined (even though I have it defined) and if I take out the parenthesis I get the same as SprintsMcGee. If I just leave the parenthesis empty I get the “toUpperCase” issue again. I must not be understanding something about calling the functions and the arguments/parameters.

Can you show me the code where you call on scorerPrompt()? Is it returning word?

I was able to figure it out, or accidentally figure it out. For my code, instead of putting in scoringAlgorithms[0].scorerFunction(word) for each of my if/else statements I put in scoringAlgorithms[0].scorerFunction(initialWord) (initial word coming from the initialPrompt function). It cleared up all the problems I had through part B. I kinda get why I had to do that, but at the same time I don’t get it

You all saved me a lot of headache with trying to figure out this part!! So thank you all!

Unrelated to the topics above. I managed to get to the end of the code past the algorithms and currently cannot understand what the goal is for the last part of the assignment. Do we actually do anything for “C) Transform Scrabble Scoring” or is it just explaining to us the idea of what we are doing for the next part?

Hey Sprints,

I am curious what was done to get it to work. I have tried all of the variables in my simpleScore function without success-I am prompted with the word = word.toUpperCase error. I’m not sure why there is an issue, or what is causing the word that is passed through simpleScore function to be undefined.I have included a snippet of the code and error for reference. Any assistance or input is appreciated.


Well, the biggest difference I can see between our codes is in the scoringAlgorithms array. You only have the point functions in there. I created 3 different objects in mine with “name”, “description”, and “scorerFunction” being the 3 keys to those objects. The scorerPrompt code you have won’t be able to look for a name in the array for each point algorithm because you don’t have that setup first.

I too am getting the word = word.toUpperCase() error message, and I don’t see why. @SprintsMcGee did you have initialWord setup somewhere else in your code?


@CedricH Besides in the scorerPrompt function, the only other place I have it setup is in initialPrompt where it was already defined in the beginning. Other than that I used “word” for the 3 point algorithms. I’m not really sure why it works instead of “word”. I figured it out accidentally.

Okay cool. Let me look back on my code and see if I didn’t accidentally remove something.

Update: I figured it out. I had to let word = initialprompt() so that way the scorerPrompt() had a value to pull within the runProgram.

1 Like

I didn’t have luck changing the initialPrompt variable to initialWord… I didn’t have luck with the let word = initialPrompt() either. Where did you put that in the code?

Here is my code for the runProgram function so far @lizzymae2001
image