Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Practice Programs
  5. Display square and cube of a number from 1 to 10 in Web

Display square and cube of a number from 1 to 10 in Web

Example:1C

Write a JavaScript to display square and cube of a number from 1 to 10 in web browser

Script

<html>
    <head>
        <title>
            Displaying square and cube
        </title>
    </head>
    <body>
        <table border = 1 align ="center">
            <th> Number</th>
            <th> Square</th>
            <th>Cube</th>
            <script type "text/javascript" src="displaysqr.js"> </script>
        </table>
    </body>
</html>
for (let i = 1; i <= 10; i++) {
  document.write(
    "<tr><td>" +
      i +
      "</td><td>" +
      i * i +
      "</td><td>" +
      i * i * i +
      "</td></tr>"
  );
}

Output

Loading

Views: 12

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments