I am making a program in JavaScript
which the user enters a number (it must always be odd and greater than 13, the user can enter as many numbers as he wants.
I've done this:
var vector = new Array();
var numeros = 0;
var contador = 0;
for (var i = 1; i < 20; i++) {
document.write("El numero del medio es: " + contador + "<br>" + "De menor a mayor:" + numeros )
<p> El numero debe ser impar y mayor a 5 </p>
<input type="number" name="formulario">
<button id="mostrar">Mostrar</button>
<button id="Siguiente">Siguiente</button>
My idea is to create a field with 2 buttons, one in which the user adds all the numbers they want and presses next until finished and the one that, when pressing the show button, shows the average number of array
the and orders them from smallest to largest.
My question is: How do I assign the values entered by the user to an array?
First of all, make it clear that it is a bad practice to use
document.write
instead it can have some other element to show the results (a div for example) where we will show the messages corresponding to the procedure carried out or errors if there were any.Then your code has a syntax error, the closing braces of the
for
There are several ways to add an element to a
array
for this example push will be used , the code is commented