Advertisement
vinissh

Exerc 4

Aug 15th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Resolvendo a folha de exercicios numero 4
  2.  
  3. //Exerc 1
  4.  
  5. document.getElementById('estados').onchange = function() {
  6.     localStorage.setItem("estado", document.getElementById("estados").value);
  7. }
  8. if(localStorage.estado) {
  9.     document.getElementById('estados').value = localStorage.estado;
  10. }
  11.  
  12. //Exerc 2
  13.  
  14. function  add_left_zero(number){
  15.     if(number < 10){
  16.         return "0" + number.toString();
  17.  
  18.     }else{
  19.         return number.toString();
  20.     }
  21.  
  22. }
  23.  
  24. function format_date(timestump){
  25.     var dia = new Date(timestump).getDate();
  26.     var mes = new Date(timestump).getMonth() + 1;
  27.     var ano = new Date(timestump).getFullYear();
  28.     return dia + "-" + mes + "-" + ano;
  29. }
  30.  
  31. /*document.getElementById('confirmar_pedido').onclick = function(){
  32.     var selection = document.getElementById('envios').value;
  33.  
  34.     if(selection == "escolha"){
  35.         alert('Escolha um modelo de envio');
  36.     }else{
  37.         if(selection == "normal"){
  38.             var dias_entrega = 18;
  39.         }
  40.         else if(selection  == "express"){
  41.             var dias_entrega = 12;
  42.         }
  43.     }    
  44.  
  45.     var data_envio = new Date().getTime();
  46.     var dias_entrega = data_envio + (dias_entrega * 86400000);
  47.  
  48.     document.getElementById('data_pedido').innerHTML = format_date(data_envio);
  49.     document.getElementById('data_entrega').innerHTML = format_date(data_entrega);
  50.  
  51. }*/
  52.  
  53.  
  54. document.getElementById("confirmar_pedido").onclick = function() {
  55.  
  56.     var selection = document.getElementById("envios").value;
  57.  
  58.     if (selection == "escolha") {
  59.         alert("Escolha um modelo de envio");
  60.     } else {
  61.         if (selection == "normal") {
  62.             var dias_entrega = 18;
  63.         } else if (selection == "express") {
  64.             var dias_entrega = 12;
  65.         }
  66.  
  67.         var data_envio = new Date().getTime();
  68.         var data_entrega = data_envio + (dias_entrega * 86400000);
  69.  
  70.         document.getElementById("data_pedido").innerHTML = format_date(data_envio);
  71.         document.getElementById("data_entrega").innerHTML = format_date(data_entrega);
  72.  
  73.     }
  74.  
  75. }
  76.  
  77. //Exec 3
  78.  
  79. //Delarando as variaveis de forma global
  80. var iniciado = false, hora_inicio, init_cronometro , hora_atual, init_cronometro, tempo_passado;
  81.  
  82. document.getElementById('comecar_parar').onclick = function(){
  83.  
  84.     if(!iniciado){
  85.         iniciado = true;
  86.         document.getElementById('comecar_parar').innerHTML = "Parar";
  87.  
  88.         if(!hora_inicio){
  89.             hora_inicio = new Date.getTime();
  90.         }else {
  91.            
  92.  
  93.         }
  94.  
  95.         hora_inicio = new Date().getTime();
  96.        
  97.         init_cronometro = window.setInterval(function(){
  98.             hora_atual = new Date().getTime();
  99.             tempo_passado = hora_atual - hora_inicio;
  100.             document.getElementById('cronometro').innerHTML = tempo_passado;
  101.  
  102.         },10);
  103.        
  104.     }else {
  105.         iniciado = false;
  106.         window.clearInterval(init_cronometro);
  107.         document.getElementById('comecar_parar').innerHTML = "Começar";
  108.     }
  109.  
  110. }
  111.  
  112.  
  113.  
  114. //Exec 4
  115. var carros = [
  116.  
  117.     {
  118.         'placa': 'AAA-0198',
  119.         'caregoria': '1',
  120.     },
  121.  
  122.     {
  123.         'placa': 'HBP-2837',
  124.         'categoria': '2',
  125.     },
  126.  
  127.     {
  128.         'placa': 'PLQ-0928',
  129.         'categoria': '4',
  130.     },
  131.  
  132.     {
  133.         'placa': 'KQE-2093',
  134.         'categoria': '5',
  135.     },
  136.  
  137.     {
  138.         'placa': 'AMR-9087',
  139.         'categoria': '5',
  140.     },
  141.  
  142.     {
  143.         'placa': 'BQE-8111',
  144.         'categoria': '3',
  145.     },
  146.  
  147.     {
  148.         'placa': 'GXL-9001',
  149.         'categoria': '2',
  150.     },
  151.  
  152.     {
  153.         'placa': 'KPM-7740',
  154.         'categoria': '1',
  155.     }
  156.  
  157. ];
  158.  
  159. function valor_a_pagar(veiculo) {
  160.      
  161.     switch( veiculo.categoria){
  162.         case '1':
  163.             return 11.22;
  164.             break;
  165.         case '2':
  166.             return 22.45;
  167.             break;
  168.         case '3':
  169.             return 16.88;
  170.             break;
  171.         case '4':
  172.             return 33.65;;
  173.             break;
  174.  
  175.         default:
  176.             console.log('Veiculo de placa ' + veiculo.placa + 'não fez pagamento por erro de categoria(' + veiculo.categoria + ')');
  177.             return 0;
  178.  
  179.  
  180.     }
  181. }
  182.  
  183.  
  184. var total_arrecadado = 0;
  185.  
  186. for(var a = 0;a < carros.length; a++){
  187.     total_arrecadado += valor_a_pagar(carros[a]);
  188. }
  189.  
  190. document.getElementById('faturamento_total').innerHTML = total_arrecadado.toFixed(2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement