Hallo, maybe someone can help me.
Where did i a mistake in this code?
You haven’t defined the variable ‘a’ yet - did you want to use the ‘countdown’ variable instead like below:
var countdown = 5;
while(countdown >= 1) {
document.write("I'll see u in " + countdown + "! ");
countdown--;
}
Ah - your script attribute is set incorrectly, you have test
instead of text
meaning it should look like this: <script type="text/javascript">
OMG!!! THANK U VERY MUCH!!! I was about to give up, could not see that mistake at all. THX a lot again))))))))))))))))))))))))!!!
<script>
</script>
will do...
I did not understand #28 “While loop input” answer in JavaScript.
What is “inp”
ex.1
let num = parseInt(inp);
Hi bjamRaz.
In the solution, the inp
is defined as the result of the user input, like this:
var inp = prompt("Enter a number");
This means that, if the user input the number 10, then the variable inp
will contain the number 10.
So if you:
console.log(inp)
The result in the console would be:
10
Now back to the example:
parseInt(inp);
inp is refering to:
var inp = prompt("Enter a number");
in the line above as in the solution.
Also, inp
is just as short way of writing input
.
It’s the same as writing:
var resultFromUserInput = prompt("Enter a number");
var number = parseInt(resultFromUserInput);
var counter = 0;
While (counter < number) {
console.log(counter);
counter++;
}
I hope this made it clearer for you. I would advise you to read more on how variables work.
You can read more here:
W3Schools variables
Good luck!
I see, thanks for that. And what is the difference between parseFloat() and parseInt?
Hi, bjamRez.
I’m sorry for the late reply, you probably already figured it out by now, but I’ll add a link to a great page explaining the difference between parseInt() and parseFloat().
Difference between parseInt() and parseFloat()
Good luck!