I'm tying to create a countdown timer for online test using JavaScript in asp.net core. I want it to change every 1 second without refreshing the page. when I run the program it doesn't show me the countdown.
This my javascript code:
<script type="text/javascript">
countdown = function () {
var current = parseInt(document.getElementById("timerLabel").innerHTML);
document.getElementById("left").innerHTML = current;
if (current > 0) {
setTimeout('countdown()', 1000); // run every second
}}
This is my view: I used foreach loop to show this.
<div class="panel-footer">
<p> @item.Grade</p>
<p> @item.StartTime</p>
<p id="EndTime"> @item.EndTime</p>
<span id="timerLabel">@ViewBag.LeftTime</span>
<p id="left"></p>
</div>