Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
Data Structure Javascript: How to create simple calculator with prompt

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Main issue

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);

Other thoughts

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");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!