Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let inputOne = document.querySelector('#inputOne');
- let inputTwo = document.querySelector('#inputTwo');
- let toqueFinal = new Audio("urna.mp3");
- let toqueBotao = new Audio("botao.mp3");
- let presidents = {
- "13": {
- "nome": "Alberto Fujimori",
- "partido": "Mudança"
- },
- "17": {
- "nome": "Benito Mussolini",
- "partido": "Partido Fascista Republicano"
- }
- };
- function choosePresident() {
- if (inputOne.value.length && inputTwo.value.length) {
- let number = parseInt(inputOne.value + inputTwo.value);
- let president = presidents[number];
- document.querySelector('#nome').innerHTML = president.nome;
- document.querySelector('#partido').innerHTML = president.partido;
- elementsToHide.forEach((el) => {
- el.style.visibility = 'visible';
- });
- }
- }
- function inputEmpty () { // return input to enter a number
- if (!inputTwo.value.length && !inputOne.value.length) {
- return inputOne;
- } else if (inputOne.value.length && !inputTwo.value.length) {
- return inputTwo;
- }
- }
- elementsToHide = document.querySelectorAll('#hide');
- elementsToHide.forEach((el) => {
- el.style.visibility = 'hidden';
- });
- // event listeners
- for (let i=0; i<10; i++) { // event listener to all buttons
- document.querySelector(`#b${i}`).addEventListener('click', (msg) => {
- let btn = msg.path[0];
- let input = inputEmpty();
- input.value = btn.value;
- toqueBotao.play();
- choosePresident();
- });
- }
- inputTwo.addEventListener('keypress', function() {
- choosePresident();
- });
- document.querySelector("#confirmar").addEventListener('click', () => {
- console.log(toqueFinal);
- toqueFinal.play();
- });
- document.querySelector("#corrige").addEventListener('click', function() {
- location.reload();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement