I have to stack 3 values that are entered by the user through the prompt, and then unpack, showing the result on the screen.
The problem is that after the user types the 3 values, the following word appears 3 times, instead of the values:
undefined
How can I fix this error and stack and unstack correctly? Thanks in advance for the 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>