Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda