I'm trying to make a simple webpage with javascript. The html works fine, but I can't get the javascript to run. I wanted to know if anyone could give me an idea what was wrong with it?
The html and javascript file and are both in the same folder and I made sure I didn't do anything careless
Here's the code:
var intOne;
var intTwo;
var sec;
window.alert("Testing")
function checkAnswer()
{
if(quiz.outer.answerbox.value === intOne+intTwo)
{
alert("You smart. You loyal.");
alert("Answer is " + parseInt(intOne+intTwo));
} else {
alert("Another One.");
quiz.outer.answerbox.value="";
}
}
function displayQuestion()
{
intOne = Math.floor((Math.random() * 100) + 1);
intTwo = Math.floor((Math.random() * 100) + 1);
document.getElementById('quiz.outer.question').innerText= "What is " + intOne + " + " + intTwo + "?";
quiz.answerbox.value="";
startTimer();
}
function startTimer()
{
sec = 0;
window.setInterval(updateTime(), 1000);
}
function updateTime()
{
sec++
timer.innerText=sec;
}
<!Doctype html>
<html>
<head>
<title>Adding Quiz</title>
<script type="text/javascript" src="addingNumbers"></script>
</head>
<body onload="displayQuestion()">
<h1>Adding Quiz<h1>
<div style="color:blue">
<form name="quiz" action="#">
<p id="outer">
<p id="question">something</p>
<input type="output" id="answerbox" value=""><br>
<input type="button" value="Check" onClick="checkAnswer()">
</p>
</div>
<br>
<p>Time spent on this question so far: <strong id="timer">0</strong> seconds </p>
</body>
</html>
Oddly enough, the javascript appeared to work when i was posting the snippet, as I received an alert when I ran the code.