mercredi 13 juillet 2016

Random generator showing correct time mixed in with incorrect times

Using javascript I can create a hours and minutes clock. Here is the code.

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<style>
    .clock  {
        font-size:30px;
        border:0px solid #fff;
        font-family:Arial, sans-serif
    }
</style>
<script language="JavaScript">
var timerID = null
var timerRunning = false

function stopclock(){
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function startclock(){
    stopclock()
    showtime()
}

function showtime(){
    var now = new Date()
    var hours = now.getHours()
    var minutes = now.getMinutes()
    var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue  += (hours >= 12) ? " P.M." : " A.M."
    document.clock.face.value = timeValue 
    timerID = setTimeout("showtime()",1000)
    timerRunning = true
}
</script>
</head>
<body onLoad="startclock()">
<form name="clock" onSubmit="0">
<input TYPE="text" NAME="face" SIZE="8" VALUE ="....Initializing...." class="clock">
</form>
</body>
</html>

My problem is that I would like to create a random generator to show this output randomly mixed in with other incorrect times. These incorrect times do not need to be randomly generated but can come from an array of times. As the clock is not showing seconds the generator can show either the correct time or the wrong time every 3 seconds.

Any help gratefully received.




Aucun commentaire:

Enregistrer un commentaire