Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- document.write("This task is for creating and editing various types of arrays. <br>");
- document.write("First,we create an integer array with random numbers. <br>");
- 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)];
- document.write("Here is a rng array:" + rngarray + ". <br>");
- var rngpowerof3 = [];
- document.write("Now we power the rng array elements by 3. <br>");
- for(i = 0;i<rngarray.length;i++)
- {
- rngpowerof3[i] = Math.pow(rngarray[i],3);
- }
- document.write("The final result is: " + rngpowerof3 + " . <br>");
- document.write("Now we create random array of marks. <br>");
- 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)];
- document.write("The array is the following: " + rngmarks + ". <br>");
- var marksbetween3and4 = [];
- document.write("Now we collect the marks between 3 and 4. <br>");
- for(i = 0;i<rngmarks.length;i++)
- {
- if(rngmarks[i] >= 3 && rngmarks[i] <= 4)
- {
- marksbetween3and4.push(rngmarks[i]);
- }
- }
- document.write("Here is the result: " + marksbetween3and4 + " . <br>");
- document.write("Now we make the sum and the multiplication of the square roots of the first random number array. <br>");
- var rngarraysquareroot = [];
- var rngarraysquarerootmult = 0;
- var rngarrsquarerootsum = 0;
- for(i = 0;i<rngarray.length;i++)
- {
- rngarraysquareroot[i] = Math.floor(Math.sqrt(rngarray[i]));
- rngarraysquarerootmult *= rngarraysquareroot[i];
- rngarraysquarerootsum += rngarraysquareroot[i];
- }
- 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