I wrote a simple JavaScript code that allows people to enter a number and it should return either FizzBuzz, Fizz, Buzz or just the number if it did not meet the conditions of the FizzBuzz game. I then tried to create a button in HTML with the following code:
<button onclick="fBCalc(prompt("Enter a number!"))">FizzBuzz</button>
I have also tried this:
<input type="button" name="FizzBuzz" value="FizzBuzz" onClick="fBCalc(prompt("Enter a number!"))" />
Both methods did not work. I have searched Google for an answer but I have tried them and nothing happens when I click the button. I made sure that the function was called correctly. This works without the button so I do not know why it shouldn't work with a button. Unless a button is unable to prompt o.o. Does anyone know what is wrong?
Here is a pastebin to my full HTML code: http://pastebin.com/YPGdbTVQ
You haven't pasted your code properly here, but I did spy what I suspect is your issue on your Pastebin:
<button onclick="fBCalc(prompt("Enter a number!"))">FizzBuzz</button>
You can't put quotes inside of quotes the way you have here, because the browser can't figure out which ones do what. Try swapping the inner quotes with single-quotes:
<button onclick="fBCalc(prompt('Enter a number!'))">FizzBuzz</button>
Coincidentally, good luck with your grades! ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With