Advertisement
renix1

script

Oct 18th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let inputOne = document.querySelector('#inputOne');
  2. let inputTwo = document.querySelector('#inputTwo');
  3. let toqueFinal = new Audio("urna.mp3");
  4. let toqueBotao = new Audio("botao.mp3");
  5. let presidents = {
  6.     "13": {
  7.         "nome": "Alberto Fujimori",
  8.         "partido": "Mudança"
  9.     },
  10.     "17": {
  11.         "nome": "Benito Mussolini",
  12.         "partido": "Partido Fascista Republicano"
  13.     }
  14. };
  15.  
  16. function choosePresident() {
  17.     if (inputOne.value.length && inputTwo.value.length) {
  18.         let number = parseInt(inputOne.value + inputTwo.value);
  19.         let president = presidents[number];
  20.         document.querySelector('#nome').innerHTML = president.nome;
  21.         document.querySelector('#partido').innerHTML = president.partido;
  22.         elementsToHide.forEach((el) => {
  23.             el.style.visibility = 'visible';
  24.         });
  25.     }
  26. }
  27.  
  28. function inputEmpty () { // return input to enter a number
  29.     if (!inputTwo.value.length && !inputOne.value.length) {
  30.         return inputOne;
  31.     } else if (inputOne.value.length && !inputTwo.value.length) {
  32.         return inputTwo;
  33.     }
  34. }
  35.  
  36. elementsToHide = document.querySelectorAll('#hide');
  37. elementsToHide.forEach((el) => {
  38.     el.style.visibility = 'hidden';
  39. });
  40.  
  41. // event listeners
  42. for (let i=0; i<10; i++) { // event listener to all buttons
  43.     document.querySelector(`#b${i}`).addEventListener('click', (msg) => {
  44.         let btn = msg.path[0];
  45.         let input = inputEmpty();
  46.         input.value = btn.value;
  47.         toqueBotao.play();
  48.         choosePresident();
  49.     });
  50. }
  51.  
  52.  
  53. inputTwo.addEventListener('keypress', function() {
  54.     choosePresident();
  55. });
  56.  
  57. document.querySelector("#confirmar").addEventListener('click', () => {
  58.     console.log(toqueFinal);
  59.     toqueFinal.play();
  60. });
  61.  
  62. document.querySelector("#corrige").addEventListener('click', function() {
  63.     location.reload();
  64. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement