It is necessary to bring the elements of the array, entered through the function suma by another function Vivod, to the list in the html document itself. Sum Works correctly, there is an array. Code:

<!DOCTYPE html> <html> <head> <title>Практическая работа 5.4</title> <meta charset= "UTF-8"> <script> function suma(){ for (i=0; x !== 0; i++){ x = parseInt(prompt("введите число:",'')); numbers[i] = x; if (( x % 5 === 0) && (x === 5)) {sum += x;} if (x > 0) {pro *= x;} } } //вот тут ошибка, что не так? function Vivod(){ var size; document.open(); document.write("<ol>"); for(size = 0; size < i-1; size ++){ document.write("<li>"); document.write(numbers[i]); document.write("</li>"); } document.write("</ol>"); document.close(); } </script> </head> <body> <script> var sum=0; var pro=1; var x=1; var i; var numbers = []; suma(); </script> <table height=200 width=300 border="solid" cellspacing=1> <tr> <td>Сумма чисел, кратных 5: <script>document.write(sum)</script></td> </tr> <tr> <td>Произведение положительных чисел: <script>document.write(pro)</script></td> </tr> </table> <script> vivod(); </script> </body> </html> 

  • What is myWindow variable? Where is it initialized? - Stepan Kasyanenko February
  • @StepanKasyanenko is a mistake, I checked something there, just document.write there. I will correct now. But even so it does not work - adam_k February
  • Already better. You have a function name - Vivod , and you vivod() . Register matters! - Stepan Kasyanenko Feb.
  • @StepanKasyanenko thanks, now he makes a list, but at each point Undefined. Why? - adam_k pm
  • Can numbers[i] be replaced by numbers[size] ? - Stepan Kasyanenko Feb.

1 answer 1

Complete condition of the problem:
Add numbers that are multiples of 5 and calculate the product of positive numbers. The input of numbers must be completed when dialing the number 0. The numbers should be output in the document as a numbered list and the calculation results should be arranged in the form of a table.


 <!DOCTYPE html> <html> <head> <title>Практическая работа 5.4</title> <meta charset= "UTF-8"> <script> function suma(){ for (i=0; x !== 0; i++){ x = parseInt(prompt("введите число:",'')); numbers[i] = x; if (( x % 5 === 0) && (x === 5)) {sum += x;} if (x > 0) {pro *= x;} } } function Vivod(){ var size; document.open(); document.write("<ol>"); for(size = 0; size < i-1; size ++){ document.write("<li>"); document.write(numbers[size]); document.write("</li>"); } document.write("</ol>"); document.close(); } </script> </head> <body> <script> var sum=0; var pro=1; var x=1; var i; var numbers = []; suma(); </script> <table height=200 width=300 border="solid" cellspacing=1> <tr> <td>Сумма чисел, кратных 5: <script>document.write(sum)</script></td> </tr> <tr> <td>Произведение положительных чисел: <script>document.write(pro)</script></td> </tr> </table> <script> Vivod(); </script> </body> </html>