Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda