In this function, I initialize the variable allowDial()
and later define it.
I was having some problems with its value so I added a console.log to the end of the offHook()
function. I define it right before. No matter what I set allowDial
to, it returns undefined - be it number, boolean, string, etc.
Why is console.log returning undefined? If I can't get console.log to accurately report its value, I don't see how I can make this implementation of the variable work.
Here is the relevant code:
var allowDial;
var availableNumbers = ["0", "911", "1 (847) 765-1008" , "867-5309", "1 (212) 456-1414", "555-1212", "555-5555"];
function numberSuggestion() {
var randomNumber = Math.floor(Math.random() * (availableNumbers.length));
var suggestedNumber = availableNumbers[randomNumber];
document.getElementById("suggestion").innerHTML = "How about dialing <strong id='suggestedTelephoneNumber'>" + suggestedNumber + "</strong>? Don't like this number? Click the button above again!";
}
var dialTone;
function offHook() {
document.getElementById("WE2500").style.display = "none";
document.getElementById("dialPad").style.display = "block";
dialTone = new Audio('dialTone.m4a');
dialTone.play();
allowDial === true;
console.log(allowDial);
}