Making a do while loop on HTML5

i was trying to get my code right when i had to make a do while loop and i tried asking my user the capital of United States and the answer must be “Washington” so i needed to make it perform an action of restricting the user from making more than 3 trials, please anyone there who understand what i’m saying, I’m stalked

What have you tried so far?

Can you put an example in codepen?

<!DOCTYPE html>
<html>
<head>
	<title>Working With Do While Loop</title>
</head>
<body>
<h1>Working With Do While Loop</h1>

<script>
	do{
		var answer = prompt("Capital Of United States?");

	} while (answer != 'Washington');
</script>

</body>
</html>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

Okay Randell, thank you so much

You could declare a variable like numPrompts before the do…while loop and initialize it to 0. Then inside the loop you could increment numPrompts by one. Then you would just need to add a second condition in addition to the the answer != 'Washington', so that you validate numPrompts is less than 3.