Reputation: 49
I'm trying to change a button's onclick function to remove one function and add two functions. This is my current code
var random;
function number(){
var random =Math.floor(Math.random()*Math.floor(Math.random()*20))
}
function show(){
var display = document.getElementById('number').innerHTML= random;
}
function start(){
var random =Math.floor(Math.random()*Math.floor(Math.random()*20))
var button = document.getElementById('button').innerHTML="I give up!!";
var change = document.getElementById("button").onclick = show; number;
}
Upvotes: 1
Views: 237
Reputation: 55750
Add 2 event listeners to your button
function start(){
var random = Math.floor(Math.random()*Math.floor(Math.random()*20)),
button = document.getElementById('button').innerHTML="I give up!!";
changeButton = document.getElementById("button");
changeButton.addEventListener('click', show);
changeButton.addEventListener('click', number);
}
Upvotes: 1
Reputation: 193301
You need to assign onclick
an anonymous function and include both functions in it:
document.getElementById("button").onclick = function() {
show();
number();
};
Upvotes: 1