Having trouble opening the prompt window by clicking on the button

I have been given an assignment to check if a given number is an Armstrong number. However, I am facing an issue where the prompt window does not appear when I click the button. This issue only arises when the rest of the function is written out. If the function is standalone, the prompt window functions correctly.

function armNum(){
    var num = prompt("Enter a number between 0 and 999!: ");
    var firstNum;
    var secondNum;
    var thirdNum;
    if(num < 100 && num > 0)
    {
        firstNum = num/10;
        secondNum = num%10;
        var StrongNum = (firstNum**3) + (secondNum**3);
        if( num == StrongNum)
        {
            document.getElementById("ispis").innerHTML = "number " + num + " is an Armstrong number!";
        }
        else
        {
            document.getElementById("ispis").innerHTML = "number " + num + " is not an Armstrong number!";
        }
    }
    if(num > 99 && num < 1000)
    {
        firstNum = num/100;
        secondNum = (num/10)%10;
        thirdNum = num % 10;
        var StrongNum = (firstNum**3) + (secondNum**3) = (thirdNum**3);
        if( num == StrongNum)
        {
            document.getElementById("ispis").innerHTML = "number " + num + " is an Armstrong number!";
        }
        else
        {
            document.getElementById("ispis").innerHTML = "number " + num + " is not an Armstrong number!";
        }
    }
}

Answer №1

  1. There is an error in this line (replace "=" with "+"):

    var StrongNum = (firstNum3) + (secondNum3) = (thirdNum**3);

  2. You forgot to call a function

  3. Remember to include this line after your function:

    armNum();

Answer №2

There is an error in this line

= (firstNum**3) + (secondNum**3) = (thirdNum**3);
you have used '=' instead of '+' & you

function checkArmstrongNumber(){
    var number = prompt("Please enter a number between 0 and 999!: ");
    var firstNum;
    var secondNum;
    var thirdNum;
    if(number < 100 && number > 0)
    {
        firstNum = number/10;
        secondNum = number%10;
        var strongNum = (firstNum**3) + (secondNum**3);
        if( number == strongNum)
        {
            alert( "Number " + number + " is an Armstrong number!")
        }
    else

        {
            alert( "Number " + number + " is not an Armstrong number!");        }
    }
    if(number > 99 && number < 1000)
    {
        firstNum = number/100;
        secondNum = (number/10)%10;
        thirdNum = number % 10;
        var strongNum = (firstNum**3) + (secondNum**3)+(thirdNum**3);
        if( number == strongNum)
        {
            alert( "Number " + number + " is an Armstrong number!");
        }
        else
        {
            alert("Number " + number + " is not an Armstrong number!");
        }
    }
}
<body onload=checkArmstrongNumber()>
</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

jquery unclean data, in need of the jquery ui popup dialog

I have been experimenting with this library to determine if a form is dirty. By default, it triggers the standard browser confirmation asking whether you are certain about navigating away from the page. The jquery dirtyforms website includes a section sugg ...

"Learn how to seamlessly submit a form without reloading the page and send data back to the same page using Node and Express

I've already reviewed a few questions on this platform. They all focus on submitting post requests, but I believe the process should be similar for get requests as well. Therefore, I made modifications to my code to accommodate get requests. However, ...

Addressing the Summer Note Problem within a Bootstrap Popup

I am currently facing an issue with the functionality of the Summernote Text plugin in my project. The text inside the Summernote editor does not display what I am typing until I resize the browser window. Below is the code snippet for reference: <%-- ...

Combine the bootstrap button and dropdown menu side by side and adjust the width of the dropdown to be

Snippet: <div class="d-grid gap-2 d-md-block mt-1"> <button class="btn btn-secondary" id="btnSearch"><i class="fa fa-search fa-fw"></i>Search</button> <button class="btn ...

Dynamic Column Image and Text Display

I am working on a website where I am trying to have an image on the left and a paragraph on the right, but when the screen size is reduced, I need the layout to switch so that the image is at the top and the paragraph is at the bottom. Even though I have ...

While typing, React-hook-form is removing the input field when the mode property is enabled

Currently, I am implementing a basic form using react-hook-form version 7 along with Material UI. However, I have encountered an unusual behavior when configuring the mode in useForm({mode: ".."}). Below is a snippet of my code: import { yupResol ...

Having trouble finding two p-col-6 elements side by side in the PrimeNG FlexGrid with Angular?

I have integrated Flex Grid into my Angular7 project. In the initial state, I am able to display two p-col-6 elements side by side without any issues. However, when I try to rearrange them in p-col-12, they no longer align properly. Here is a detailed expl ...

Where is the best place to import Bootstrap in my SCSS file when customizing it with Sass?

When attempting to customize bootstrap using Sass, I discovered that overriding default bootstrap variables can be quite confusing. I am curious if someone could provide an explanation for the inconsistent behavior. Some variables only seem to be overridd ...

AngularJS - Swipe to update

I've been trying to use the pull to refresh plugin for Angular JS, but unfortunately it's not working for me. Even though I can see the text, when I try to pull nothing happens! I followed all the steps outlined on this GitHub page: https://githu ...

javascript issue with fetching data from URL using the GET method

Here is my attempt to fetch a JSON file from a server using asynchronous JavaScript promises. I am experiencing an issue where the result is undefined when using a specific URL, but it works when I use a different URL. Below is the working code with a dif ...

Enhance your Vue app by dynamically modifying classes with Tailwind

I am working on a Vue3 application that utilizes Tailwinds configured in the tailwind.config.js file. My question is, can I dynamically modify the value of a preconfigured class from the tailwind.config.js file? For instance: tailwind.config.js: const d ...

Internet Explorer and Edge browsers are concealing box shadow behind the parent div

When using an input slider range, the box-shadow is being applied to the active thumb in all browsers except for IE & EDGE. In these browsers, the shadow is cutting or hiding behind the parent div #c. I have already tried setting overflow:visible on the p ...

What are the steps to executing commands with child processes in Node.js?

I have successfully established communication between the client and server using socket.io. I am now utilizing WebSockets to send commands from the client to the server, and I would like to execute these received commands on the server. Here is my approa ...

Looping through required fields in jQuery based on a CSS class

Is there a way to loop through required fields marked with <input class="required">? Currently, only the first input in the loop is being evaluated. How can I traverse the DOM using a loop to check all input boxes? Thank you for your help. While I ...

Enhancing IntelliJ IDEA's autocomplete functionality with JavaScript libraries

Is there a way to add my custom JavaScript library to IntelliJ IDEA 10.5 or 11 for autocomplete functionality? I want to specify that IDEA should recognize and suggest auto-completions for objects from my library. While it sometimes works automatically, ...

Effortless Sidebar Navigation for populating primary content

Initially, I must confess that even though this seems like a straightforward issue, I am just as puzzled as you are by my inability to solve it independently. With no prior experience in web development, I find myself in need of using GitHub Pages to docum ...

Does the gltf loader in three.js have compatibility issues with Internet Explorer 11?

Despite the claims on the official website that gltf files should load in three.js scenes using IE11, I have been experiencing issues with the loader. Even the examples provided by three.js fail to work on Internet Explorer when it comes to loading gltf fi ...

Is there a way to automatically extend my content to fill the space on the page below the Material UI AppBar?

I am currently using React and Material UI React to develop my application. My goal is to implement the AppBar component with content underneath, without causing the entire page to scroll. I want the content to occupy the maximum remaining height and the f ...

Unidentified variable in Angular Ajax function when accessed outside its scope

Currently, I am in the process of creating a ticket admin table. However, I am facing some challenges with exporting a variable outside of an ajax function. Here is my code: app.controller('bodyController',function($scope,$http,$sce){ $scope.ti ...

"Dynamic Addition of Textboxes to Webpages with the Help of jQuery

Currently, I am facing a challenge in adding a textbox to a webpage in ASP.NET MVC using jQuery. My goal is to have a button that, when clicked, appends a text box to the existing collection of Textboxes with a specified class. Below is the jQuery code sni ...