Home > database >  Don't understand this error in javascript within my html file: ',' expected.javascrip
Don't understand this error in javascript within my html file: ',' expected.javascrip

Time:04-29

I apologize for the silly request, but I am brand new to HTML and JavaScript and am trying to self-teach. My code right now is based off a resource I found that teaches you how to make a timer. My only question is, why does line 16 (var seconds...) come up with the error in the title, specifically with the red line under "var"? Thank you in advance. Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

<p id="demo"></p>

<script>
var x = setInterval(function() {
    var timer = 600;
    var minutes = Math.floor(timer // 60);
    var seconds = Math.floor(timer % 60);
    document.getElementById("demo").innerHTML = minutes   "minutes and "   seconds   "seconds";
    if (timer < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED"
}
    }, 1000);
</script>
    </h2>
    <a href="html/contact.html">Contact Information</a>
</body>
</html>

CodePudding user response:

You will probably find this is to do with line 15, being commented out at character 37, I think instead of putting / you've ended up putting // which comments out in js

from my testing, removing the secondary / fixes the issue with the code you pasted

what you had:

    var timer = 600;
    var minutes = Math.floor(timer // 60);
    var seconds = Math.floor(timer % 60);

what works for me

    var timer = 600;
    var minutes = Math.floor(timer / 60);
    var seconds = Math.floor(timer % 60);
  • Related