-1

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);
}
InterLinked
  • 1,247
  • 2
  • 18
  • 50

2 Answers2

1

You are not assigning any value to allowDial. === is used for comparison, not assignment. For assigning a value you should use allowDial = true;

pkgajulapalli
  • 1,066
  • 3
  • 20
  • 44
-3

You don't assign any value to allowDial.

allowDial = true;

Example:

var tmp;
testVar(tmp);       // "is null"
tmp = null;
testVar(tmp);       // "is null""is definitive null"

testVar()

function testVar(variable) {
  if(variable == null) { 
    console.log("is null");
  } 

  if(variable === null) { 
    console.log("is definitive null");
  }
}
da-chiller
  • 156
  • 1
  • 13
  • You have completely misunderstood the difference between `==` and `===`. http://stackoverflow.com/questions/523643/difference-between-and-in-javascript – Lennholm May 19 '17 at 12:34
  • @MikaelLennholm: Jepp, until a couple moments I was sure. Shame on me!!! – da-chiller May 19 '17 at 12:38