Created
July 18, 2020 00:47
-
-
Save gabizinha12/6489cb641f1206b2723842b7bf6246f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let num = document.querySelector('input#fnum') | |
let lista = document.querySelector('select#flista') | |
let res = document.querySelector('div#res') | |
let valores = [] | |
function isNumero(n) { | |
if (Number(n) >= 1 && Number(n) <= 100) { | |
return true | |
} else { | |
return false | |
} | |
} | |
function inLista(n, l) { | |
if (l.indexOf(Number(n) != -1)) { | |
return true | |
} else { | |
return false | |
} | |
} | |
function adicionar() { | |
if (isNumero(num.value) && !inLista(num.value, valores)) { | |
valores.push(Number(num.value)) | |
let item = document.createElement('option') | |
item.text = `Valor ${num.value} adicionado.` | |
lista.appendChild(item) | |
} else { | |
window.alert('Valor inválido ou já encontrado na lista') | |
} | |
num.value = '' | |
num.focus() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment