javaScript: Reading and Querying and Recording Cookies [closed]

1

The home screen shows an off lamp. The lamp image was found at:

http://imagensxti.xpg.uol.com.br/img/xlamp_off.png

Also shows a time display mask.

Below is the code for the page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>JavaScript - Cookies </title>
        <style type="text/css">
            body { background-color:#000; }
            #xti { display:block; margin:20px auto; }
            #horas {color:#fff; margin:0 auto; width:110px; font-size:30px};
        </style>
        <script type="text/javascript" src="js/cookie.js"></script>
        <script type="text/javascript" src="js/Aula39.js"></script>
    </head>
    <body>
        <img id="xti"  
            src="img/xlamp_off.png" />

        <div id="horas">00:00:00</div>

    </body>
</html>

With the click of a mouse on top of the figure, activate the connect function, the following should occur:

In the Aula39.js script file, the linking function displays a picture of a lightbulb accessed from:

http://imagensxti.xpg.uol.com.br/img/xlamp_on.png

The mostrarHoras function displays the current time in 1 second intervals;

In the coockie.js file, the readCookie function checks for coockie by sending a greeting if there is a user or a prompt for the username entry, as shown below:

window.onload = function() {
document.getElementById("xti").onclick = ligar;
setInterval(mostrarHoras, 1000);

var nome = readCookie("nome");
    if(nome == null) {
    nome = prompt("Qual o seu nome?");
    writeCookie("nome", nome, 1);
    }
}

function ligar() {
document.getElementById("xti").src = "img/xlamp_on.png";

    var nome = readCookie("nome");
        if(nome != null){
            alert("Como vai? " + nome);
    }

setTimeout(desligar, 3000);
}

function desligar() {
document.getElementById("xti").src = "img/xlamp_off.png";
}

function mostrarHoras() {
var agora = new Date();
var horas = agora.getHours() + ":" + agora.getMinutes() +  ":" + agora.getSeconds();
document.getElementById("horas").innerHTML = horas;
}

The readCookie function is considered undefined, and the rest of the coockie function, as listed in the coockie.js script, are not running.

function writeCookie(name, value, days){
//Por default, nâo existe expiração, ou seja o cookie é temporário
var expires = "";

//Especifica o número de dias para guardar o cookie
if (days) {
var date = new Date();
date.setTime(date.getTime)() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}

if(value != "" && value != null && value != "null"){
//Define o cookie com o nome, valor e data de expiração
document.cookie = name + "=" + value + expires + "; path=/";
}
}

function  (name) {
//Encontra o cookie especificado e retorna o seu valor
var searchName = name + "=";
var cookies = document.cookie.split(';');
for(var i=0; i < cookies.length; i++) {
var c = cookies [i];
while (c.chartAt(0) == ' ')
c = c.substring(1, c.length);
if (c.indexOf(searchName) == 0)
   return c.substring(searchName.length, c.length);
  }
  return null;
}

function eraseCookie(name){  
//Exclui o cookie
  writeCookie(name, "", -1);
  }

I wish that if someone knew what could be the reason, help me to continue the task. I am grateful.

    
asked by anonymous 27.10.2017 / 16:55

0 answers