Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Assignment 4.7</title>
- </head>
- <body>
- <h3>Write a program of Armstrong Series</h3>
- <hr>
- <script type="text/javascript">
- // Take input a number from user
- var userInput = Number(prompt('Enter a number to print Armstrong Series...'));
- // Displaying number which is entered by user
- document.write('Entered number by you = <strong>' + userInput + '</strong><br><br>');
- // Displaying series of armstrong number
- for (var i = 0; i <= userInput; i++) {
- var temp = 0; //it will store calculation of evetry number to check its armstrong or not
- var splittedArray = String(i).split(''); // it will store array for of every number
- for (x in splittedArray) {
- temp += ((Number(splittedArray[x])) ** splittedArray.length); // here done the calculation for armstrong number
- }
- if (i === temp) {
- document.write(i + "<br>"); // here displaying the armstrong number if it is
- }
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment