is that I have been having a problem with my code, due to the fact that I want to make some inputs disappear/appear when I give a specific number, for example, if I want to say that I have in "number of notes" 3, I want that 3 inputs appear to me to enter the 3 notes and their specific button, and so, if I want 4, then the 4 inputs and the specific button appear, but I don't know how, can someone help me? I was thinking that instead of using an input to say how many notes I have I could use buttons but that's another topic. By the way, the code is used to get averages. Thank you
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
<title>
PROMEDIOS
</title>
</head>
<body>
<h1>Cantidad de notas</h1>
<input type="text" name="nNotas">
<button onclick="subNotas()">listo</button>
<h1>ingresa tus notas</h1>
<input type="text" placeholder="Nota #1" name="nota1"><br>
<input type="text" placeholder="Nota #2" name="nota2">
<br>
<input type="text" placeholder="Nota #3" name="nota3">
<br>
<input type="text" placeholder="Nota #4" name="nota4">
<br>
<input type="text" placeholder="Nota #5" name="nota5"><br>
<button onclick="sub()">2 Notas</button><br>
<button onclick="sub2()">3 Notas</button><br>
<button onclick="sub3()">4 Notas</button><br>
<button onclick="sub4()">5 Notas</button><br>
<label id="suma"></label>
<script>function subNotas(){
nNotas = document.getElementsByName("nNotas")[0].value;
if (nNotas == 2) {
nota1=true;
nota2=true;
}
else if (nNotas <=0) {
alert ("error")
}
else if (nNotas >=6) {
alert ("error")
}
}
function sub(){
nota1 = document.getElementsByName("nota1")[0].value;
nota2 = document.getElementsByName("nota2")[0].value;
var total= Number(nota1) + Number(nota2);
var pro1= total/2;
document.querySelector("#suma").textContent = pro1;
}
function sub2(){
nota1 = document.getElementsByName("nota1")[0].value;
nota2 = document.getElementsByName("nota2")[0].value;
nota3 = document.getElementsByName("nota3")[0].value;
var total= Number(nota1) + Number(nota2) + Number(nota3);
var pro2= total/3;
document.querySelector("#suma").textContent = pro2;
}
function sub3(){
nota1 = document.getElementsByName("nota1")[0].value;
nota2 = document.getElementsByName("nota2")[0].value;
nota3 = document.getElementsByName("nota3")[0].value;
nota4 = document.getElementsByName("nota4")[0].value;
var total= Number(nota1) + Number(nota2) + Number(nota3) + Number(nota4);
var pro3= total/4;
document.querySelector("#suma").textContent = pro3;
}
function sub4(){
nota1 = document.getElementsByName("nota1")[0].value;
nota2 = document.getElementsByName("nota2")[0].value;
nota3 = document.getElementsByName("nota3")[0].value;
nota4 = document.getElementsByName("nota4")[0].value;
nota5 = document.getElementsByName("nota5")[0].value;
var total= Number(nota1) + Number(nota2) + Number(nota3) + Number(nota4) + Number(nota5);
var pro4= total/5;
document.querySelector("#suma").textContent = pro4;
}
</script>
</body>
</html>