am_dot_com

SW 2023-03-31

Mar 31st, 2023 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pt">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Numeração Romana</title>
  6. <script src="2.js"></script>
  7. </head>
  8. <body>
  9. <!-- mecanismo de input -->
  10. <form>
  11. <fieldset>
  12. <legend lang="pt">
  13. Fronteira de valores, a visualizar
  14. em numeração romana
  15. </legend>
  16. <label for="idNInicial">Valor inicial: </label>
  17. <input
  18. id="idNInicial"
  19. name="nameNInicial"
  20. type="number"
  21. min="1"
  22. max="1000"
  23. step="1"
  24. placeholder="aqui o valor inicial"
  25. value="1"
  26. ><br>
  27. <label for="idNFinal">Valor final: </label>
  28. <input
  29. id="idNFinal"
  30. name="nameNFinal"
  31. type="number"
  32. min="1"
  33. max="1000"
  34. step="1"
  35. placeholder="aqui o valor final"
  36. value="10"
  37. ><br>
  38. <label>Mostrar correspondência decimal: </label>
  39. <input
  40. type="checkbox"
  41. checked
  42. id="idCheckMostrar">
  43. </fieldset>
  44. <input
  45. id="idBtnObter"
  46. name="nameBtnObter"
  47. type="button"
  48. value="Obter lista em numeração romana"
  49. >
  50. </form>
  51. <hr><!-- quebra semântica -->
  52. <!-- zona de respostas -->
  53. <section
  54. name="nameSectionResposta"
  55. id="idSectionResposta"
  56. >
  57. <!-- AQUI CONTEÚDO -->
  58. <!-- no JS, esta zona tem nome: innerHTML -->
  59. <p>Aqui aparecerá a resposta</p>
  60. </section>
  61.  
  62. </body>
  63. </html>
  64.  
  65. **********
  66.  
  67. // 2.js
  68. /*
  69. load - é o evento que ocorre quando TODOS os documentos
  70. necessários para a solução, foram efetivamente
  71. carregados em memória
  72. onload - é o "event handler"
  73. */
  74. //window.onload = comoEuQueroReagirAoEventoDeLoad;
  75. window.onload = boot
  76.  
  77. // ids de objetos relevantes no HTML
  78. const ID_N_INICIAL = "idNInicial";
  79. const ID_N_FINAL = "idNFinal";
  80. const ID_BTN_OBTER = "idBtnObter";
  81. const ID_SECTION_RESPOSTA = "idSectionResposta";
  82. const ID_CHECK_MOSTRAR = "idCheckMostrar"
  83.  
  84. // declarar objetos para casar com o HTML relevante
  85. var oNInicial,
  86. oNFinal,
  87. oBtnObter,
  88. oSectionResposta,
  89. oCheckMostrar;
  90.  
  91.  
  92. /*
  93. recebido o id de um QUALQUER elemento HTML,
  94. esta função retorna um objeto JS que lhe corresponde;
  95. na realidade "um objeto que É aquele elemento".
  96. */
  97. function id(pIdHtmlElement){
  98. return document.getElementById(pIdHtmlElement)
  99. }//id
  100.  
  101. // esta função não é chamada por nós, os programadores;
  102. // esta função é AUTOMAGICAMENTE chamada pelo cliente
  103. // quando ele (antropomorfização) achar que deve chamá-la
  104. function boot(){
  105. // associações
  106. oNInicial = id(ID_N_INICIAL);
  107. oNFinal = id(ID_N_FINAL);
  108. oBtnObter = id(ID_BTN_OBTER);
  109. oSectionResposta = id(ID_SECTION_RESPOSTA);
  110. oCheckMostrar = id(ID_CHECK_MOSTRAR);
  111.  
  112. // comportamentos
  113. //oBtnObter.onclick = nomeDaFuncaoComQueQueremosResponder
  114. oBtnObter.onclick = mostrarListaDeValoresEmRomano;
  115. }//boot
  116.  
  117. function mostrarListaDeValoresEmRomano(){
  118. //window.alert("FEITO!")
  119. nInicial = Number(oNInicial.value) // String->Number
  120. nFinal = Number(oNFinal.value) // String->Number
  121. bProblema = nInicial>nFinal
  122.  
  123. if(bProblema) {
  124. window.alert("Pf, escreve um num final MAIOR que o inicial.")
  125. return;
  126. }//if
  127.  
  128. var strHTML = "<ol type='i'>"
  129. // computação
  130. for(
  131. valorAtual = nFinal; //init
  132. valorAtual >= nInicial; //continuidade
  133. valorAtual-=1 //atualização
  134. ){
  135. //fazer o quê?
  136. if (oCheckMostrar.checked)
  137. strHTML += "<li>"+valorAtual+"</li>";
  138. else
  139. strHTML += "<li></li>"
  140. }//for
  141. strHTML += "</ol>"
  142.  
  143. oSectionResposta.innerHTML = strHTML;
  144. }
  145.  
  146.  
Advertisement
Add Comment
Please, Sign In to add comment