I want to know why my console won't log the appropriate logs. The error is saying that my .addEventListener()
is null but how so?
I tried:
Removing return false
but that didn't help.
Here's gameTime.html
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="gameTime.js"></script>
<meta charset="utf-8">
<title>WOMP</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="gameTime.css">
</head>
<body>
<form class="col-md-4 col-md-offset-4" name="formHandler" id="handle">
<div id="allFields">
<div class="moveUsername">
<h1>(All numbers inputted will be assumed that it's in dollars)</h1>
<label for="usr">What's your annual salary?</label>
<input type="field" class="form-control" id="salary" placeholder="What's your annual salary?" required="required">
</div>
<div class="ageMovement">
<label for="usr">How much do you spend every month on bills?</label>
<input type="field" class="form-control" id="monthlyBills" name="ageChecker" placeholder="How much do you spend every month on bills?" required="required">
</div>
<div class="emailMovement">
<label for="usr">How much do you spend when going out?</label>
<input type="field" class="form-control" id="goingOut" name="emailChecker" placeholder="How much do you spend when going out?" required="required">
</div>
<button type="submit" id="btnSubmit" class="btn btn-default">Submit</button>
</form>
</body>
</html>
Here's gameTime.js
(function() {
function Finance(salary, fixedExpense, variableExpense) {
this.salary = salary;
this.fixedExpense = fixedExpense;
this.variableExpense = variableExpense;
this.isSalaryZeroOrLess = function() {
var s = parseInt(document.getElementById("salary").value);
console.log(this);
if (s <= 0) {
console.log("No money");
} else if (this.greaterThan()) {
console.log("Testing");
} else {
console.log("Money: ", s);
}
}
}
Finance.prototype.greaterThan = function() {
var s = parseInt(document.getElementById("salary").value);
var userSalary = s / 12;
console.log(userSalary);
if (userSalary < 30000) {
console.log("works!");
}
}
var fin = new Finance(1000, 1000, 1000);
document.querySelector("#btnSubmit").addEventListener("click", fin.isSalaryZeroOrLess);
return false;
})()
Here are the errors:
Uncaught TypeError: Cannot read property 'addEventListener' of null
at gameTime.js:30
at gameTime.js:32