I have an assignment for school and I’ve become stuck. They want us to prompt the user for a secret word with a Do While Loop, and it keeps prompting them until they get the word right. I figured it out with a number, but don’t know how to run a loop with a string instead of an integer. I coded an integer version. This is the code I used:
const MIN = 1;
const MAX = 10;
let secret = "javascript";
let guesses = 0; // for storing the number of guesses
let hint = ""; // for storing hint
let number = 0;
do {
// get input from user
let input = prompt(
`Please enter a number between ${MIN} and ${MAX}` + hint
);
// get the integer
number = parseStr(input);
// increase the number of guesses
guesses++;
// check input number with the secret number provide hint if needed
if (number > secret) {
hint = ", and less than " + number;
} else if (number < secret) {
hint = ", and greater than " + number;
} else if (number == secret) {
alert(`Bravo! you're correct after ${guesses} guess(es).`);
}
} while (number != secret);
How do I add this to a string?
Thanks in advance. I’m also not looking for the answer as much as I’m looking for what concept I’m missing that I need to learn or review so I can do this.