Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. //ligação dos inputs com as variaveis
  2. var nascimento = document.getElementById('ano')
  3. var nascimento_valor = Number(nascimento.value)
  4.  
  5. var sexo = document.getElementsByName('radioSexo')
  6. var texto = document.getElementById('texto')
  7. var imagem = document.createElement('img')
  8. imagem.setAttribute('id', 'foto')
  9.  
  10.  
  11.  
  12. //Verificação de dados
  13. if (nascimento_valor > ano || nascimento_valor < 1900) {
  14. alert('Por Favor verifique os dados de nascimento !!!')
  15. } else {
  16. var idade = Number(ano - nascimento_valor)
  17. }
  18.  
  19.  
  20. //Recebendo e convertendo os valores
  21. var genero = ''
  22. if (sexo[0].checked) {
  23. genero = 'masculino'
  24.  
  25. //Criando o elemento <img> para receber as imagens
  26. if (nascimento_valor >= 0 || nascimento_valor <= 10) {
  27. imagem.setAttribute('src', 'crianca-masculino.jpg')
  28.  
  29. } else if (nascimento_valor >= 11 || nascimento_valor <= 18) {
  30. imagem.setAttribute('src', 'jovem-masculino.jpg')
  31.  
  32. } else if (nascimento_valor >= 19 || nascimento_valor <= 50) {
  33. imagem.setAttribute('src', 'adulto-masculino.jpg')
  34.  
  35. } else {
  36. imagem.setAttribute('src', 'idoso-masculino.jpg')
  37. }
  38.  
  39. } else if (sexo[1].checked) {
  40. genero = 'feminino'
  41.  
  42. //Criando o elemento <img> para receber as imagens
  43. if (nascimento_valor >= 0 || nascimento_valor <= 10) {
  44. imagem.setAttribute('src', 'crianca-feminino.jpg')
  45.  
  46. } else if (nascimento_valor >= 11 || nascimento_valor <= 18) {
  47. imagem.setAttribute('src', 'jovem-feminino.jpg')
  48.  
  49. } else if (nascimento_valor >= 19 || nascimento_valor <= 50) {
  50. imagem.setAttribute('src', 'adulto-feminino.jpg')
  51.  
  52. } else {
  53. imagem.setAttribute('src', 'idoso-feminino.jpg')
  54. }
  55.  
  56. } else {
  57. alert('Você esqueceu de marcar o sexo !!!')
  58. }
  59.  
  60.  
  61. //Recebendo o texto dinamicamente
  62. texto.innerText = `Você nasceu em ${nascimento_valor}, tem ${idade} anos e gênero ${genero}`
  63. texto.appendChild(imagem)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement