Advertisement
CaptainManiac999

Stupid error in JS that I can;t find

Oct 27th, 2021
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  document.write("This task is for creating and editing various types of arrays. <br>");
  2.       document.write("First,we create an integer array with random numbers. <br>");
  3.       var rngarray = [Math.floor(Math.random(1,10)*10),Math.floor(Math.random(1,10)*10),Math.floor(Math.random(1,10)*10),Math.floor(Math.random(1,10)*10),Math.floor(Math.random(1,10)*10)];
  4.       document.write("Here is a rng array:" + rngarray + ". <br>");
  5.       var rngpowerof3 = [];
  6.       document.write("Now we power the rng array elements by 3. <br>");
  7.       for(i = 0;i<rngarray.length;i++)
  8.       {
  9.           rngpowerof3[i] = Math.pow(rngarray[i],3);
  10.       }
  11.       document.write("The final result is: " + rngpowerof3 +  " . <br>");
  12.       document.write("Now we create random array of marks. <br>");
  13.       var rngmarks = [Math.floor(Math.random(2,6) * 10),Math.floor(Math.random(2,6) * 10),Math.floor(Math.random(2,6)*10),Math.floor(Math.random(2.6)*10),Math.floor(Math.random(2,6) *10),Math.floor(Math.random(2.6)*10)];
  14.       document.write("The array is the following: " + rngmarks + ". <br>");
  15.       var marksbetween3and4 = [];
  16.       document.write("Now we collect the marks between 3 and 4. <br>");
  17.       for(i = 0;i<rngmarks.length;i++)
  18.       {
  19.           if(rngmarks[i] >= 3 && rngmarks[i] <= 4)
  20.           {
  21.               marksbetween3and4.push(rngmarks[i]);
  22.           }
  23.       }
  24.       document.write("Here is the result: " + marksbetween3and4 + " . <br>");
  25.       document.write("Now we make the sum and the multiplication of the square roots of the first random number array. <br>");
  26.       var rngarraysquareroot = [];
  27.       var rngarraysquarerootmult = 0;
  28.       var rngarrsquarerootsum = 0;
  29.       for(i = 0;i<rngarray.length;i++)
  30.       {
  31.          rngarraysquareroot[i] = Math.floor(Math.sqrt(rngarray[i]));
  32.          rngarraysquarerootmult *= rngarraysquareroot[i];
  33.          rngarraysquarerootsum += rngarraysquareroot[i];
  34.       }
  35.       document.write("Here are the results: <br> The square root integer array is: " + rngarraysquareroot + " <br>" + " The multiplication of square roots is: " + rngarraysquarerootmult + " <br>" + "The sum of square roots is: " + rngarraysquarerootsum + " <br>");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement