I have task to create simple calculator. That task required using prompt and alert for the answer. So I do this
let i = prompt('input');
while(i = 0) {
x++;
i = prompt('input');
}
alert(x);
that code give me alert, but not process the number
I have advise to make that value saved in system
I do
let i = prompt('input');
const i =[]
while(i = 0) {
x++;
i = prompt('input');
}
alert(x);
and you know that is, make error. I tried again to move the const
const i =[]
let i = prompt('input');
while(i = 0) {
x++;
i = prompt('input');
}
alert(x);
and still error.
I'm beginner programmer. I have this task because I'm not be able to do more advance thing before understanding data structure
I just don't know how to write logic in computer. I know the task, but I don't know how to write the code.
may be you have advice how to learn data structure more easely
thank's
Your first block of code has a few things that need to be fixed.
let i = prompt('input');
while(i = 0) {
x++;
i = prompt('input');
}
alert(x);
This block will give an error because x is never declared. Let's declare it after (or before) declaring the i variable:
let i = prompt('input');
let x = 0;
Another issue is the condition in the while loop block:
while (i = 0) {
In the condition, we are assigning 0 to the i variable, but we want to use a comparison operator (use == or ===):
while(i == 0) {
The following fixes are applied to block one:
let i = prompt('input');
let x = 0;
while (i == 0) {
x++;
i = prompt('input');
}
alert(x);
Re-declaring constants (const) as you are doing in boxes two and three is not allowed, so that needs to be changed. If you want to create a constant array (const i = []) then you can always change the elements within the constant array (such as Array.push).
const i = [];
i.push("someValue");