Question

In: Computer Science

Write, test, and debug (if necessary) HTML file with the Javascript codes in an external file...

Write, test, and debug (if necessary) HTML file with the Javascript codes in an external file for the following problem:

Input: a number, n, using prompt, which is the number of the factorial numbers to be displayed.

Output: a bordered table of numbers with proper caption and headings in which the first column displays the numbers from 1 to n and the second column displays the first n factorial numbers.

For example, if a user enters 10 to be the value of n, the first column will include 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and the second column will include 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800.

Your Javascript codes must include a function to compute the factorial number given an input number. This function is to be called to generate corresponding factorial number for each number in the first column of the table. You must use document.write to produce the desired output. Use the external CSS document for the display of the table.

Solutions

Expert Solution

If you have any problem with the code feel free to comment.

HTML

<!DOCTYPE html>

<html>

    <head>

        <title>Factorial</title>

        <link rel="stylesheet" href="style.css" />

    </head>

    <body>

        <script type="text/javascript" src="test.js"></script>

    </body>

</html>

CSS

body {

    width: 100%;

}

/* centering the table */

table {

    margin: 0 auto;

    text-align: center;

    border-collapse: collapse;

}

/* providing border to the table */

td {

    border: 2px solid black;

    padding: 10px;

}

/* changing the background color of table header */

.table-header {

    background-color: beige;

    font-size: 20px;

}

JAVASCRIPT

var n = parseInt(prompt('Enter the number'));//taking user input

//showing table structure

document.write('<table>');

document.write('<tr class="table-header">');

document.write('<td>Value</td>');    

document.write('<td>Factorial</td> </tr>');    

for(i=1; i<=n; i++){//traversing the user input

var f = findFactorial(i);

document.write('<tr><td>'+i+'</td>');    

document.write('<td>'+f+'</td> </tr>');   

}

document.write('</table>');

function findFactorial(value){//finding the factorial of the number

    var fact=1, j;

    for(j=1; j<=value; j++){

        fact = fact * j;

    }

    return fact;

}

OUTPUT


Related Solutions

Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the HTML file that references the JavaScript file. Use prompt to collect names of persons from the user. When the user enters ‘DONE’, your script should stop collecting more names. Then, it should ask the user to specify the following style properties: Border size? 2px, 5px, or 8px. Border Color? blue, red, green, and black. Border style? solid, dotted, dashed, and double. The HTML document...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the...
Write, test, and debug (if necessary) JavaScript scripts for the following problem. You must write the HTML file that references the JavaScript file. Use prompt to collect names of persons from the user. When the user enters ‘DONE’, your script should stop collecting more names. Then, it should ask the user to specify the following style properties: - Border size? 2px, 5px, or 8px. - Border Color? blue, red, green, and black. - Border style? solid, dotted, dashed, and double....
For both JavaScript and HTML: ---------------------------------------------------- Write and test JavaScript scripts for the two exercises that...
For both JavaScript and HTML: ---------------------------------------------------- Write and test JavaScript scripts for the two exercises that follow, debug (if necessary).  When required to write a function, you must include a script to test the function with at least two different data sets.  In all cases, for testing, you must write an HTML file that references the JavaScript file. Output an HTML table of the numbers from 2 to 8 along with their squares and cubes. Create a function titled counter that takes...
This needs to be written in JavaScript with two files. One HTML file and a JavaScript...
This needs to be written in JavaScript with two files. One HTML file and a JavaScript file. Make an empty HTML file, put three buttons inside the body and an empty main tag below the buttons. The text of the buttons should be "Foo", "Bar", and "FooBar" respectively. Don't put the " in the buttons that's just for clarification in these instructions. Add unique IDs to each button In your JavaScript, get 3 separate references to the buttons using the...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file that uses createElement and appendChild to dynamically insert three paragraphs when a button is clicked. (b) Create a HTML file that includes JavaScript that is similar to: let recs = [“my item …1”,”my item…2”, …] i.e. an array that contains several CSV item records. When the user clicks a button, each array element will be rendered as a list element. Use a HTML list....
Build an application using HTML, CSS, javascript, json. It is not necessary for backend to be...
Build an application using HTML, CSS, javascript, json. It is not necessary for backend to be working but the frontend should be good. App should to simple and useful in our day to day life. For eg- grocery shopping list or alarm or weather forecast or reminder.
For this assignment, you will write a tic-tac-toe application in HTML and JavaScript, using an HTML...
For this assignment, you will write a tic-tac-toe application in HTML and JavaScript, using an HTML <canvas> tag. The game will be played "hot seat" where players take turns using the same device. Requirements: The canvas should be 600px tall and wide, with the gameplay area occupying most of the canvas. The X's and O's may be drawn using polygons or large-font text The grid should be drawn using polygons, specifically long, thin rectangles Before & between games, the canvas...
This should be done in JavaScript. The HTML file should only contain an empty main tag....
This should be done in JavaScript. The HTML file should only contain an empty main tag. All other HTML on the page should be created with JavaScript. The JavaScript file should be a separate file.   Make an empty HTML file, put an empty main tag inside the body. In your JavaScript, use querySelector to get a reference to the main tag and save it in a variable named main. Look up three good jokes and store them as separate variables...
Based on the descriptions given below, write the JavaScript codes to calculate the amount to be...
Based on the descriptions given below, write the JavaScript codes to calculate the amount to be paid for books purchased.  Declare all the variables used in this program.  Ask the user to key-in the book code using a prompt() method. Store the value in a variable named book_code.  Ask the user to key-in the number of books purchased using a prompt() method. Store the value in a variable named book_qty.  Ask the user whether they have...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT