<input type="button" id="blue" value="pick one" onClick="pickMyArray();" />
<br/>
<div id="output">
Hello Dr Eaglin! Please press the button to select student for automatic A for this class.
</div>
JavaScript
//can't seem to get this to work. Up top in the DOM the buttton is set and onclick is calling the function.
// myArray is set globally
var myArray = ["Kristopher", "Ignacio", "Vanessa", "Charlene", "Casey", "Christian", "Adnane",
"Nicholas", "Ronald", "Andrew"
];
function pickMyArray () {
//random is set by built in function to randomly pick from myArray given its array length.
var random = myArray[Math.floor(Math.random() * myArray.length)];
//this gets the random variable and assigns it to output
document.getElementById("output").innerHTML = random;
//then it should be able to be read in div id as I understand it. I also couldn't get your JS fiddle for the first assignment to work. Are there extensions I need to apply?
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.