admin管理员组

文章数量:1311153

I'm unsure why this isn't executing properly? It's so simple however I can't warp my head around it:

response = prompt(question.toLowerCase());

When I insert something into the prompt and I console.log it it seems to e back with uppercase letter that I added when I inserted the value into the prompt.

I want toLowerCase to convert any value into lowercase when submitted.

Any idea why this isn't working?

I'm unsure why this isn't executing properly? It's so simple however I can't warp my head around it:

response = prompt(question.toLowerCase());

When I insert something into the prompt and I console.log it it seems to e back with uppercase letter that I added when I inserted the value into the prompt.

I want toLowerCase to convert any value into lowercase when submitted.

Any idea why this isn't working?

Share Improve this question asked Dec 26, 2015 at 11:29 Nicholas MaddrenNicholas Maddren 1555 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

It's because you are setting lower caption of prompt, not the entered text. You have to use:

response = prompt(question).toLowerCase();

As you want toLowerCase() to convert any user response to lowercase, try

resp = prompt('Blah blah', '')
lcrp = response.toLowerCase();

As prompt or window.prompt accepts two arguments, one for the message to be displayed in the prompt and another as a default if the user did not provide any response.

prompt returns the user input as a string. So, resp.toLowerCase() should convert resp to lowercase.

本文标签: javascriptPrompt toLowerCase not executing correctlyStack Overflow