-3
I need to do a class exercise from a parking system, follow the HTML format:
<head>
<meta charset="utf-8"/>
<title>Estacionamento</title>
<script type="text/javascript" src="jquery.js"></script>
<style type="text/css">
fieldset { width:250px; }
label { display:block; float:left; }
label, input, textarea, select { width:150px; margin: 5px 0; }
th, td { border:1px solid #ccc; font-size:0.9em; }
</style>
</head>
<body>
<form id="formulario">
<fieldset>
<legend>Estacionamento</legend>
<label for="tempoPermanencia" >Informe o tempo de permanencia:</label>
<input type="text" id="tempoPermanencia" name="tempoPermanencia" /><br /><br />
<button type="button" id="button" onclick="calcular()">Calcular</button><br /><br />
<label for="total" >Total a pagar:</label>
<input type="text" id="total" name="total" readonly="readonly"/><br /><br />
</fieldset>
</form>
<script type="text/javascript" src="estacionamento.js"></script>
</body>
The rules of parking are:
3,00 every hour 30.00 daily
# A partir de 3hs 4,00 a cada 30 min
var array = [];
function calcular(){
var tempoPermanencia = $("#tempoPermanencia").val();
var totalAcumulado = 0;
var estacionamento = new Object();
estacionamento['tempoPermanencia'] = tempoPermanencia;
estacionamento['totalAcumulado'] = totalAcumulado;
array.push(estacionamento);
for (i = 0; i < array.length; i++){
var hora = $("#tempoPermanencia").val().split(":");
if (array[i].tempoPermanencia >= "01:00"){
if(hora[1] == "00"){
totalAcumulado += 5 * hora[0];
}
else if(hora[1] != "00"){
totalAcumulado += (5 * hora[0]) + 2.5;
console.log(hora);
}
}else if (array[i].tempoPermanencia == "00:30"){
totalAcumulado += 2.5;
}
else if (array[i].tempoPermanencia == "24:00"){
totalAcumulado += 50;
}
else if (array[i].tempoPermanencia >= "03:00"){
if(hora[1] == "00"){
totalAcumulado += (hora[0] * 2) * 2;
console.log(hora);
}else if(hora[1] != "00"){
totalAcumulado += (hora[0] * 2 + 1) * 2;
console.log(hora);
}
}
//$("#total").val(totalAcumulado);
//$("#tempoPermanencia").val("");
//$("#tempoPermanencia").focus();
}
$("#total").val(totalAcumulado);
$("#tempoPermanencia").val("");
$("#tempoPermanencia").focus();
}
I did it this way but I would like to check if there is a more efficient way, I believe mine is making mistakes too... Thank you all
Do you "believe it contains errors"? The teacher did not teach you to check for errors on the console?
– Sam
Errors in not being 100% meeting what the exercise asks for... Not showing syntax error
– user156519