Where is the error?

Asked

Viewed 50 times

-4

Good people, I would like to put a watch on a website that I am making but nothing appears :( I wonder if you could give me a little help?

Thanks in advance.

HTML:

<!doctype html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Yantramanav:100,300,400,500,700,900" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="Style-index.css">
<title>Marucos</title>
<script type="text/javascript">
function relogio(){
    var data = new date();
    var horas = data.gethours();
    var minutos = data.getminutes();
    var segundos = data.getseconds();

    if(horas < 10){
    horas="0"+horas;

    if(minutos < 10){
    minutos="0"+minutos;

    if(segundos < 10){
    segundos="0"+segundos;
    }
    document.getElementById("relogio").innerHTML=horas+":"+minutos+":"+segundos;
}
window.setInterval("relogio()",1000);
</script>
<style type="text/css"></style>
</head>

<body background='Imagens/background-index01.jpg' onload="relogio();">
<audio src="Músicas/Laura Branigan - Self Control.mp3" autoplay loop></audio>

<div id="relógio"></div>






<a href="page01.html"><div style=""><video class="center" width="500" height="300" autoplay loop>
                            <source src="Videos/Produce.mp4" type="video/mp4">
                      </video></div></a>
<a href="https://www.skype.com/pt"><div style=""><img class="padding bottom left" src="Imagens/skype.png" width="30" height="30"></div></a>
<a href="https://www.whatsapp.com"><div style=""><img class="padding bottom left" src="Imagens/whatsapp-messenger.png" width="30" height="30"></div></a>

</body>
</html>

CSS:

#menu ul{
    width:300px;
    height: auto;
    background-color:#2f4f4f;
    display:block;
    margin:0;
    padding:0;
    width:306px;
    cursor:pointer;
}

#menu li{
    list-style:none;
    display: block;
    width:100%;
    height:auto;
    border-bottom:2px solid #fff;
    color:#fffafa;
    font-family: helvetica;
    font-size: 20px;
    padding: 20px;
    text-align: center;
}

#menu li:hover{
    background: #ff4500;
    width: 266px;
}

#menu li{
    -webkit-transition:all .9s ease;
    -moz-transition:all .9s ease;
    -ms-transition:all .9s ease;
    transition:all .9s ease;
}

h1{
    font-family:helvetica;
    color: #8fbc8f;
}

.center{
    padding-top:15%;
    padding-left:35%;
}

body{
    background-image: Imagens/background-index01.jpg;
    background-repeat: no-repeat;
    background-size: cover;
    margin: center;
    padding: 50px 60px;
}

#relogio{
    color:#f90;
    font:bold 48px Arial;
    padding:50px;
}

1 answer

3


Your problem is Javascript errors. Let’s see:

function relogio(){
    var data = new date();
    var horas = data.gethours();
    var minutos = data.getminutes();
    var segundos = data.getseconds();

    if(horas < 10){
    horas="0"+horas;

    if(minutos < 10){
    minutos="0"+minutos;

    if(segundos < 10){
    segundos="0"+segundos;
    }
    document.getElementById("relogio").innerHTML=horas+":"+minutos+":"+segundos;
}
window.setInterval("relogio()",1000);
<div id="relógio"></div>

There are several mistakes here:

  • Use new Date();, and not new date(); - If you don’t use uppercase and lowercase letters correctly, it will go wrong!

  • Use getHours, getMinutes and getSeconds instead of gethours, getminutes and getseconds. Again, paying attention to upper/lower case is extremely important!

  • You use three { in their blocks if, but ends only one with }. Don’t let the ifs wide open.

  • You search for the element relogio, but declares an element in HTML relógio. Just as case and lowercase differences are important, accent differences are also important.

  • You use window.setInterval("relogio()",1000);. There is no reason to put the function call as a string, so use only window.setInterval(relogio, 1000);.

Here’s how your complete code looks fixed. Click the blue button Execute down below to check it running.

#menu ul {
    width: 300px;
    height: auto;
    background-color:#2f4f4f;
    display: block;
    margin: 0;
    padding: 0;
    width: 306px;
    cursor: pointer;
}

#menu li {
    list-style: none;
    display: block;
    width: 100%;
    height: auto;
    border-bottom: 2px solid #fff;
    color: #fffafa;
    font-family: helvetica;
    font-size: 20px;
    padding: 20px;
    text-align: center;
}

#menu li:hover {
    background: #ff4500;
    width: 266px;
}

#menu li {
    -webkit-transition:all .9s ease;
    -moz-transition:all .9s ease;
    -ms-transition:all .9s ease;
    transition:all .9s ease;
}

h1 {
    font-family: helvetica;
    color: #8fbc8f;
}

.center {
    padding-top: 15%;
    padding-left: 35%;
}

body {
    background-image: Imagens/background-index01.jpg;
    background-repeat: no-repeat;
    background-size: cover;
    margin: center;
    padding: 50px 60px;
}

#relogio {
    color: #f90;
    font: bold 48px Arial;
    padding: 50px;
}
<!doctype html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Yantramanav:100,300,400,500,700,900" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="Style-index.css">
<title>Marucos</title>
<script type="text/javascript">
function relogio() {
    var data = new Date();
    var horas = data.getHours();
    var minutos = data.getMinutes();
    var segundos = data.getSeconds();

    if (horas < 10) horas = "0" + horas;

    if (minutos < 10) minutos = "0" + minutos;

    if (segundos < 10) segundos = "0" + segundos;
    document.getElementById("relogio").innerHTML = horas + ":" + minutos + ":" + segundos;
}
window.setInterval(relogio, 1000);
</script>
<style type="text/css"></style>
</head>

<body background='Imagens/background-index01.jpg' onload="relogio();">
<audio src="Músicas/Laura Branigan - Self Control.mp3" autoplay loop></audio>

<div id="relogio"></div>






<a href="page01.html"><div style=""><video class="center" width="500" height="300" autoplay loop>
                            <source src="Videos/Produce.mp4" type="video/mp4">
                      </video></div></a>
<a href="https://www.skype.com/pt"><div style=""><img class="padding bottom left" src="Imagens/skype.png" width="30" height="30"></div></a>
<a href="https://www.whatsapp.com"><div style=""><img class="padding bottom left" src="Imagens/whatsapp-messenger.png" width="30" height="30"></div></a>

</body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.