Ask coding questions

← Back to all posts
I'm not sure how to assign a script to a button
MatthewX

i tried assigning the script to onclick for the html button. i also tried writing the function in between <script></script>, but it didnt work. Is there any other way to assign a script to a button???

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
MatthewX
Comments
hotnewtop
Coder100

Hi! You are confusing javascript with java...

Here's the fixed code.

MatthewX

@Coder100 Oh, i didnt know that my bad.

MatthewX

@Coder100 wait, but how do i assign the code to the onclick event for the button?

Coder100

onclick="infernoa()" @MatthewX

Coder100

for your HTML tag @MatthewX

Coder100

so your code becomes:

@MatthewX

MatthewX

@Coder100 wdym by some code. Do I write the code where the arrows are?

MatthewX

@Coder100nvm i got it

MatthewX

@Coder100 But how come the random attack does like 90 dmg i want it to do around 0-20 dmg

MatthewX

@Coder100 And also do you have an idea of how to add a health thing like Health: {} where you can change it whenever the health is loss?

MatthewX

@Coder100 nvm about the random thing.

ironblockhd

You use java functions but you have to use javascript (they're not the same)

ironblockhd

Here's a working example: https://pokemon.ironblockhd.repl.co