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

417
Vistas
how do i make two if statements with seperate conditions execute at the same time

I'm very new to coding, only learning HTML & CSS about a year ago and just learning javascript about a week ago. I decided to create a cookie clicker-type project in order to try and improve my JS skills and everything works fine except for one thing. These two if statements i have below are not executing together. I want to make them both execute so that if the banana count is equal to 10,000 then it should add a single farm and also change the html elements.

The reason they are two seperate if statements is that I had to add a second condition (!addFarm1) to check if a var is false then make it true so that it only adds the farm once instead of every click after 10,000 banana counts.

How i want it to work is that once banana count reaches 10000, a single farm is added to the farm count and ALSO changes the html elements to match the 'upgrade' then changes the interval. There is much more code but i didnt know if i should post it so i just posted the important parts but please ask if you need the rest of the code to fix it.

var addFarm1 = false;

function countByTwo(num1) {
    for (let i = 0; i < num1; i++) {
        bananaCount += 2;
    }
    return bananaCount;
}

function addFarm(farmAdd) {
    farmCount = farmCount + farmAdd;
    farmCountText.textContent = farmCount;
    farmIncrementText.classList.remove('hidden');

    farmIncrement = farmCount * 5;
    farmIncrementText.textContent = '+' + farmIncrement;

    setInterval(function() {
        bananaCount = bananaCount + farmIncrement;
        bananaCountText.textContent = bananaCount;
    }, 1000);
}

function bananaClick() {
    bananaCount += 1;

    if (bananaCount > 10000) { // this one to change the clicker image, text, and interval
        bananaClicked.textContent = 'Golden Banana Bunch (+15)';
        banana.src = 'images/banana6.png';
        countByTwo(3);
    }

    bananaCountText.textContent = bananaCount;
}

if (bananaCount > 10000 && !addFarm1) { // and this one to add one farm
    addFarm(1);
    addFarm1 = true;
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You could do something like:

if (bananaCount > 10000) { // this one to change the clicker image, text, and interval
    bananaClicked.textContent = 'Golden Banana Bunch (+15)';
    banana.src = 'images/banana6.png';
    countByTwo(3);

    if(!addFarm1) {
        addFarm(1);
        addFarm1 = true;
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Simply put both if statements in the function.

function bananaClick() {
  bananaCount += 1;

  if (bananaCount > 10000) { // this one to change the clicker image, text, and interval
    bananaClicked.textContent = 'Golden Banana Bunch (+15)';
    banana.src = 'images/banana6.png';
    countByTwo(3);
  }
  if (bananaCount > 10000 && !addFarm1) { // and this one to add one farm
    addFarm(1);
    addFarm1 = true;
  }
  bananaCountText.textContent = bananaCount;
}
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