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

112
Views
My HTML button is not working, or it wont call my javascript function

I am new to coding, and i am trying to make a game in javascript. I don't know why my HTML button is not calling my javascript function. I have tried moving the button to the bottom of the code, I have tried it with different functions, I have looked on some reference sites and i can't figure out why it is not working. Here is my button:

let waveActive = false;
let waveNumber = 0;
let enemyCount = 4;
let enemyAmount = 0;
let enemyHealth = 30;

function newWave() {
  enemyCount + 25 %
    Math.floor(enemyCount);
  enemyHealth + 10 %
    Math.floor(enemyHealth);
}

function startWave() {
  waveNumber + 1;
  waveActive = true;
  newWave()
  class enemySpawn {
    main(Stringargs) {
      int(i = enemyAmount)
      while (i < enemyCount) {
        Enemy = new component(30, 30, "purple", 10, 120);
        enemyAmount + 1;
      }
    }
    enemyAmount = 0;
  }
}
<div name="buttonDiv">
  <button type="button" id="startRoundBtn" onclick=startWave();>Start Round</button>
</div>

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

0

Try to increment your wave number. waveNumber + 1 will not change the property.

waveNumber += 1;

Here too (along with other places):

function newWave() {
  enemyCount = enemyCount + 25 %
    Math.floor(enemyCount);
  enemyHealth = enemyHealth + 10 %
    Math.floor(enemyHealth);
}

The other issue is your class definition inside your click handler.

You probably do not need the main function. It seems you want something more like this

class EnemySpawn {
  constructor(...args) {
     // do stuff here
  }
}

enemyAmount = 0;  // not sure if you even want to reset this...

while (enemyAmount < enemyCount) {
 const enemy = new EnemySpawn(30, 30, "purple", 10, 120);
 enemyAmount += 1;
}
about 4 years ago · Juan Pablo Isaza Report

0

Try it in Script tag in html it should work. Below code is working for me :)

<div name="buttonDiv">
  <button type="button" id="startRoundBtn" onclick="startWave();">
    Start Round
  </button>
</div>

<script>
    let waveActive = false;
let waveNumber = 0;
let enemyCount = 4;
let enemyAmount = 0;
let enemyHealth = 30;
function newWave() {
enemyCount + 25%
Math.floor(enemyCount);
enemyHealth + 10%
Math.floor(enemyHealth);
}
function startWave() {
  waveNumber + 1;
  waveActive = true;
  newWave()
  class enemySpawn {
     main(Stringargs) {
        int(i = enemyAmount)
        while (i < enemyCount) {
            Enemy = new component(30, 30, "purple", 10, 120);
            enemyAmount + 1;
       }
    }
    enemyAmount = 0;
  }
}
</script>
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!