+ 3
Execute a javascript function with html button?
How would I execute this external javascript function with html? function wordGen() { var wordList = ["Array", "Function", "Boolean", "Null", "Undefined", "Number", "String", "Symbol", "Object"]; var rand = Math.floor(Math.random() * wordList.length); return wordList[rand]; }
5 Answers
+ 13
Use the onclick atrribute of the <button> tag.
One more thing to note is that the function returns a value and not actually print it on the screen..So I used console.log() function to show the value.
Feel free to ask if you don't understand :)
https://code.sololearn.com/WF8vBc4YamT4/?ref=app
+ 8
Nikhil Beat me to it. :>
https://code.sololearn.com/WBmjSGA6lkIn/?ref=app
+ 2
Thank you,
I am in my second week of a full stack coding bootcamp. Everything is coming at me really fast.
+ 2
May be this code can help youđđđđ«đ«đ«
https://code.sololearn.com/WpR8qrTKmfRi/?ref=app
+ 1
If you are attending a Bootcamp I will assume that you are not using Code Playground to create a website.
You will need to point to the external javascript file as an example-
<script> src="something.js"</script>
see links below for more examples and explanations
https://www.w3schools.com/js/js_whereto.asp
https://www.youtube.com/watch?v=r--dRuIiV7A