2
I have to stack 3 values that are typed by the user through the prompt, and after this pop up, showing the result on the screen.
The problem is that after the user enters the 3 values, it appears the following word 3 times, instead of the values :
Undefined
How can I fix this error and stack and pop correctly ? I thank you for your answers.
My code :
<html>
<head>
<script type="text/javascript"/>
function FIFO(){
this.fila = new Array();
this.Enfileira = function(obj){
this.fila[this.fila.length] = obj;
}
this.Desenfileira = function(){
if (this.fila.length > 0){
var obj = this.fila[0];
this.fila.splice(0,1);
return obj;
}else{
alert ("Não há objetos na fila.")
}
}
}
</script>
</head>
<body>
<h1>EXEMPLO FILA</h1>
<script type="text/javascript"/>
var minhafila = new FIFO();
minhafila.Enfileira = prompt ("Digite um texto : ");
minhafila.Enfileira = prompt ("Digite um texto : ");
minhafila.Enfileira = prompt ("Digite um texto : ");
var desenf1 = minhafila.Desenfileira();
document.write(desenf1,"</br>");
var desenf2 = minhafila.Desenfileira();
document.write(desenf2,"</br>");
var desenf3 = minhafila.Desenfileira();
document.write(desenf3,"</br>");
</script>
</body>
</html>
What do you think
minhafila.Enfileira = prompt ("Digite um texto : ");
ago?– Pablo Almeida