Question

In: Computer Science

Write JavaScript statements to accomplish each of the following tasks: a) Display the value of the...

  1. Write JavaScript statements to accomplish each of the following tasks:

    1. a) Display the value of the seventh element of array f.

    2. b) Initialize each of the five elements of one-dimensional array g to 8.

    3. c) Total the elements of array c, which contains 100 numeric elements.

    4. d) Copy 11-element array a into the first portion of array b, which contains 34 elements.

    5. e) Determine and print the smallest and largest values contained in 99-element floating-

point array w.

PLEASE WRITE ALL HTML PROGRAM IN A SINGLE PROGRAM. ALL ANSWERS SHOULD BE SOLVED IN A SINGLE OUTPUT.

Solutions

Expert Solution

Code in HTML+Javascript in single page

<!DOCTYPE html>
<html>
<title>Web Page Design</title>
<head>
<script>
function test() {
    //question a)
        //declare an array with 10 numbers
        var nums = [1,2,3,4,5,6,7,8,9,10];
        //print the seventh element of array which is at index 6
        document.write("a) Printing 7th element of array -> ", nums, "  = ");
        document.write(nums[6]);
        document.write("<br/>");
    //question b)
        //Initialize each five elements of an array g to 8
        var g = Array(5).fill(8);
        document.write("b) Array b after initializing -> ", g);
        document.write("<br/>");
        
    //question c)
        //Total the elements of array c which contains 100 numeric elements
        //contruct an array with 100 elements
        var c = [];
        arraySize=100;
        while(arraySize--) c.push(arraySize);
        var sum=0;
        for (var i = 0; i < 100; i++) sum+=c[i];
        document.write("c) Sum of 100 elements = ", sum);
        document.write("<br/>");
        
    //question d)
        //Copy 11-element array a into the first portion of array b, which contains 34 elements.
        //create b with 34 elements
        var b = [];
        arraySize=34;
        while(arraySize--) b.push(arraySize*2);
        //create a with 11 elements
        var a = [];
        arraySize=11;
        while(arraySize--) a.push(arraySize*3);
        
        document.write("d) Copying a -> ", a, "<br/>to b -> ", b);
        document.write("<br/>");
        for (var i = 0; i < 11; i++) b[i]=a[i];
        document.write("Final Array b -> ", b);
        document.write("<br/>");
        //copy a in b
    //question e)
        //Determine and print the smallest and largest values contained in 99-element floating-point array w
        //contruct an array with 99 elements
        var w = [];
        arraySize=99;
        while(arraySize--) w.push(arraySize+arraySize/100);
        var small=w[0];
        var large=w[0]
        for (var i =1; i < 99; i++) {
            if(w[i]>large) large=w[i];
            if(w[i]<small) small=w[i];
        }
        document.write("e) Smallest number = ", small);
        document.write(", Largest number = ", large);
        document.write("<br/>");
    
}
test()
</script>
</head>
<body>
</body>
</html>

Sample document output

a) Printing 7th element of array -> 1,2,3,4,5,6,7,8,9,10 = 7
b) Array b after initializing -> 8,8,8,8,8
c) Sum of 100 elements = 4950
d) Copying a -> 30,27,24,21,18,15,12,9,6,3,0
to b -> 66,64,62,60,58,56,54,52,50,48,46,44,42,40,38,36,34,32,30,28,26,24,22,20,18,16,14,12,10,8,6,4,2,0
Final Array b -> 30,27,24,21,18,15,12,9,6,3,0,44,42,40,38,36,34,32,30,28,26,24,22,20,18,16,14,12,10,8,6,4,2,0
e) Smallest number = 0, Largest number = 98.98

Let me know in comments if you have any doubts. Do leave a thumbs up if this was helpful.


Related Solutions

Using javascript, Display the following two statements about Plagiarism and Attendance in 2 paragraphs. Display a...
Using javascript, Display the following two statements about Plagiarism and Attendance in 2 paragraphs. Display a button “Switch paragraphs” between these two paragraphs. Whenever the user clicks the switch button, the 2 paragraphs switch their places. Plagiarism statement: I have read the policy for plagiarism at Wollongong University. I declare that this assignment solution is entirely my work. Button “Switch paragraphs” appears HERE. Attendance statement: I acknowledge that this assignment is scheduled to be marked in the computer lab in...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
In C++, use SML programs to accomplish each of the following tasks: a) Use a sentinel-controlled...
In C++, use SML programs to accomplish each of the following tasks: a) Use a sentinel-controlled loop to read positive numbers and compute and display their sum. Terminate input when a negative number is entered. b) Use a counter-controlled loop to read seven numbers, some positive and some negative, and compute and display their average. c) Read a series of numbers, and determine and display the largest number. The first number read indicates how many numbers should be processed. For...
Write a single C++ statement to accomplish each of the following.                               &nbs
Write a single C++ statement to accomplish each of the following.                                                  (6 pts) Read an integer from the user at the keyboard and store the value entered in an integer variable age. Compute the product of the 3 integers contained in variables x, y and z and assign the result to the variable result
Description: Write and test a MASM program to perform the following tasks: 1. Display your name...
Description: Write and test a MASM program to perform the following tasks: 1. Display your name and program title on the output screen. 2. Display instructions for the user. 3. Prompt the user to enter two numbers. 4. Calculate the sum, difference, product, (integer) quotient and remainder of the numbers. 5. Display a terminating message. Requirements: 1. The main procedure must be divided into sections:  introduction  get the data  calculate the required values  display the results...
Program Description Write and test a MASM program to perform the following tasks: Display your name...
Program Description Write and test a MASM program to perform the following tasks: Display your name and program title on the output screen. Display instructions for the user. Prompt the user to enter three numbers (A, B, C) in descending order. Calculate and display the sum and differences: (A+B, A-B, A+C, A-C, B+C, B-C, A+B+C). Display a closing message. Program Requirements The program must be fully documented and laid out according to the CS271 Style Guide. This includes a complete...
Design and implement a JavaScript program to accomplish the following: 1. Iterate and accept N test...
Design and implement a JavaScript program to accomplish the following: 1. Iterate and accept N test scores and N student names (where 10 <= N <= 20). 2. Compute the sum and average of the scores (display these values). 3. Implement a function that determines the highest score (display this value). 4. Implement a function that determines the lowest score (display this value). 5. Implement a function that determines the letter grade of each score: 90-100 (A); 80 - 89...
Write and run SQL statements to complete the following tasks Show the details of the employees...
Write and run SQL statements to complete the following tasks Show the details of the employees who are located in area code 901 and their manager employee number is 108. Show the details of the employees who are also mangers. Show the details of the customers whose balance is greater than 220 but less than 500. Show the details of the customers whose balance is highest. Show customer 10014’s name and the product’s descriptions which he/she purchased and the number...
Write and run SQL statements to complete the following tasks Show the details of the vendors...
Write and run SQL statements to complete the following tasks Show the details of the vendors who are located in area code 615. Show the details of the products that do not have a value for the attribute v_code. Show the details of the invoices whose subtotal is greater than 25 but less than 75. Show the details of the invoice who has the minimum subtotal. Show the codes and names of the vendors who supplied products. Using EXCEPT show...
Write an array method to carry out each of the following tasks for an array of...
Write an array method to carry out each of the following tasks for an array of integers. Note: you can think of each as a separate problem independent of the others. a) Swap the first and last elements in the array. b) Shi< all elements by one to the right and move the last element into the first posi>on. For example, 1 4 9 16 25 would be transformed into 25 1 4 9 16. c) Replace all even elements...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT