While loop error?
Posted
by
user134134
on Programmers
See other posts from Programmers
or by user134134
Published on 2014-05-31T21:49:21Z
Indexed on
2014/05/31
21:55 UTC
Read the original article
Hit count: 390
JavaScript
I believe the problem with my code lies within my while loop. Admittedly, I'm rather new to Javascript programming. Does this look okay:
<! DOCTYPE html>
<head><title>title</title></head>
<body>
<script type="text/javascript">
alert("Hello, stranger. Please note that at this current moment, we do not have a save function. It might be a good idea to record your answers.");
var preAnswer = 0;
while (var preAnswer = 0) {
var name = prompt("What is your name? Please capitalise it, for the sake of grammar.")
if (name === "")
{
alert("What are you playing at? You didn't type anything.");
var preAnswer = 0;
} else {
var preAnswer = 1
}
}
alert("Nice name, " + name + ", bro.")
</script>
</body>
</html>
I'm sure I've done something wrong, as it isn't functioning.
© Programmers or respective owner