59.5k views
4 votes
What is a line of code that sets user input to all lowercase characters? For this example, base it on the following line of code:

var userInput = prompt('Do you select rock, paper, or scissors)?

User Adu
by
8.2k points

1 Answer

2 votes

Final answer:

To convert user input to lowercase in JavaScript, the toLowerCase() method is used immediately after the prompt function, ensuring all characters are lowercase.

Step-by-step explanation:

To set user input to all lowercase characters in the existing line of code, you would use the toLowerCase() method in JavaScript, which is a string method that converts all the characters in a string to lowercase. Here is the modified line of code:

var userInput = prompt('Do you select rock, paper, or scissors?').toLowerCase();

This line of code first prompts the user for input and then immediately applies the toLowerCase() method to whatever string is entered by the user, ensuring that all characters in the user input are in lowercase form before storing it in the variable userInput.

User Robert Dale Smith
by
8.2k points

Related questions