What's wrong with my function?


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/5?curriculum_id=506324b3a7dffd00020bf661


I'm trying to add the additional suggested functionality to the game in the last step. I'm having trouble with several things, but I've cut it down to just a few lines here and I can't even get this part to work and I don't understand why. What is wrong with this code? The result just displays User: null


var decideUserChoice = function() {
    var userChoice = prompt("Do you choose rock, paper, scissors, or rope? Use lowercase letters only.");
    console.log("User: " + userChoice);
    
}

decideUserChoice();


#2

Reading the output "User: null" tells you that it logged from that console.log statement, and that userChoice was null at that time. The last value assigned to that variable was coming from calling prompt, so you'll have to consider if that behaved as it should have. How prompt behaves depends on the user and the environment so there's no way we can know what you did there.


#3

I don't know what the deal was. Now it's working as expected.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.