Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Resolvendo a folha de exercicios numero 4
- //Exerc 1
- document.getElementById('estados').onchange = function() {
- localStorage.setItem("estado", document.getElementById("estados").value);
- }
- if(localStorage.estado) {
- document.getElementById('estados').value = localStorage.estado;
- }
- //Exerc 2
- function add_left_zero(number){
- if(number < 10){
- return "0" + number.toString();
- }else{
- return number.toString();
- }
- }
- function format_date(timestump){
- var dia = new Date(timestump).getDate();
- var mes = new Date(timestump).getMonth() + 1;
- var ano = new Date(timestump).getFullYear();
- return dia + "-" + mes + "-" + ano;
- }
- /*document.getElementById('confirmar_pedido').onclick = function(){
- var selection = document.getElementById('envios').value;
- if(selection == "escolha"){
- alert('Escolha um modelo de envio');
- }else{
- if(selection == "normal"){
- var dias_entrega = 18;
- }
- else if(selection == "express"){
- var dias_entrega = 12;
- }
- }
- var data_envio = new Date().getTime();
- var dias_entrega = data_envio + (dias_entrega * 86400000);
- document.getElementById('data_pedido').innerHTML = format_date(data_envio);
- document.getElementById('data_entrega').innerHTML = format_date(data_entrega);
- }*/
- document.getElementById("confirmar_pedido").onclick = function() {
- var selection = document.getElementById("envios").value;
- if (selection == "escolha") {
- alert("Escolha um modelo de envio");
- } else {
- if (selection == "normal") {
- var dias_entrega = 18;
- } else if (selection == "express") {
- var dias_entrega = 12;
- }
- var data_envio = new Date().getTime();
- var data_entrega = data_envio + (dias_entrega * 86400000);
- document.getElementById("data_pedido").innerHTML = format_date(data_envio);
- document.getElementById("data_entrega").innerHTML = format_date(data_entrega);
- }
- }
- //Exec 3
- //Delarando as variaveis de forma global
- var iniciado = false, hora_inicio, init_cronometro , hora_atual, init_cronometro, tempo_passado;
- document.getElementById('comecar_parar').onclick = function(){
- if(!iniciado){
- iniciado = true;
- document.getElementById('comecar_parar').innerHTML = "Parar";
- if(!hora_inicio){
- hora_inicio = new Date.getTime();
- }else {
- }
- hora_inicio = new Date().getTime();
- init_cronometro = window.setInterval(function(){
- hora_atual = new Date().getTime();
- tempo_passado = hora_atual - hora_inicio;
- document.getElementById('cronometro').innerHTML = tempo_passado;
- },10);
- }else {
- iniciado = false;
- window.clearInterval(init_cronometro);
- document.getElementById('comecar_parar').innerHTML = "Começar";
- }
- }
- //Exec 4
- var carros = [
- {
- 'placa': 'AAA-0198',
- 'caregoria': '1',
- },
- {
- 'placa': 'HBP-2837',
- 'categoria': '2',
- },
- {
- 'placa': 'PLQ-0928',
- 'categoria': '4',
- },
- {
- 'placa': 'KQE-2093',
- 'categoria': '5',
- },
- {
- 'placa': 'AMR-9087',
- 'categoria': '5',
- },
- {
- 'placa': 'BQE-8111',
- 'categoria': '3',
- },
- {
- 'placa': 'GXL-9001',
- 'categoria': '2',
- },
- {
- 'placa': 'KPM-7740',
- 'categoria': '1',
- }
- ];
- function valor_a_pagar(veiculo) {
- switch( veiculo.categoria){
- case '1':
- return 11.22;
- break;
- case '2':
- return 22.45;
- break;
- case '3':
- return 16.88;
- break;
- case '4':
- return 33.65;;
- break;
- default:
- console.log('Veiculo de placa ' + veiculo.placa + 'não fez pagamento por erro de categoria(' + veiculo.categoria + ')');
- return 0;
- }
- }
- var total_arrecadado = 0;
- for(var a = 0;a < carros.length; a++){
- total_arrecadado += valor_a_pagar(carros[a]);
- }
- document.getElementById('faturamento_total').innerHTML = total_arrecadado.toFixed(2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement