javascript - I have a "onclick" that runs 3 functions but only runs one? -
so have button onclick runs 3 functions , each function display random symbol. when press button, should output 3 random symbols, 1 symbol outputted when click button.
<!doctype html> <html> <head> <title>myfirstjavascript</title> </head> <body> <script> function slots1() { var slot1 = math.floor(math.random()*4); if (slot1 == 0) { document.getelementbyid('value').innerhtml = "\u2663"; } if (slot1 == 1) { document.getelementbyid('value').innerhtml = "\u2665"; } if (slot1 == 2) { document.getelementbyid('value').innerhtml = "\u2666"; } if (slot1 == 3) { document.getelementbyid('value').innerhtml = "\u2660"; } } function slots2() { var slot2 = math.floor(math.random()*4); if (slot2 == 0) { document.getelementbyid('value').innerhtml = "\u2663"; } if (slot2 == 1) { document.getelementbyid('value').innerhtml = "\u2665"; } if (slot2 == 2) { document.getelementbyid('value').innerhtml = "\u2666"; } if (slot2 == 3) { document.getelementbyid('value').innerhtml = "\u2660"; } } function slots3() { var slot3 = math.floor(math.random()*4); if (slot3 == 0) { document.getelementbyid('value').innerhtml = "\u2663"; } if (slot3 == 1) { document.getelementbyid('value').innerhtml = "\u2665"; } if (slot3 == 2) { document.getelementbyid('value').innerhtml = "\u2666"; } if (slot3 == 3) { document.getelementbyid('value').innerhtml = "\u2660"; } } </script> <button type="button" value="spin" name="spin" onclick="slots1();slots2();slots3();">spin</button> <span id="value"></span> </body> </html>
each function overrides value that's changed previous one, value see result of slots3()
. following line common functions , it's override:
document.getelementbyid('value').innerhtml = //some value;
Comments
Post a Comment