最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Prompt toLowerCase not executing correctly - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论