0

Can anyone tell what is problem in the following code... when i run the program in browser a blank white screen appears... I don't know why its not working... I am not very sure with the syntax...
I don't want to invoke the function by any events.. i just want to write a function and invoke it by a manual call...

    <html>
    <head>
        <script language="javascript" type="text/javascript">
            function salin()
            {
                var sal = prompt("Enter your current salary - ","");
                var in = prompt("Enter the increment % - ","");

                sal = parseInt(sal);
                in = parseInt(in);

                var nsal = sal +( sal*(in /100));

                alert("Your new salary is - " + nsal);
            }

         salin();
      </script>
    </head>

    <body>
    </body>
    </html>
6
  • Do you see any error in console.? Commented Jul 12, 2017 at 5:06
  • no... i don't see any error Commented Jul 12, 2017 at 5:07
  • 2
    You must be getting error: "message": "Uncaught SyntaxError: Unexpected token in", Commented Jul 12, 2017 at 5:09
  • in is reserved keyword in java-script so, your variable name cannot be in Commented Jul 12, 2017 at 5:09
  • @trex1999 Where exactly are you looking? In Firefox you get SyntaxError: missing variable name. Commented Jul 12, 2017 at 5:23

4 Answers 4

5

The issue seems to be in this line in = parseInt(in);

in is a reserved keyword in javascript which is use to return a boolean value. Replace it with a different variable name

Sign up to request clarification or add additional context in comments.

Comments

3

I have created this fiddle..

Its working. You were using reserved javascript keyword

function salin()
            {
                var sal = prompt("Enter your current salary - ","");
                var values = prompt("Enter the increment % - ","");

                sal = parseInt(sal);
                values = parseInt(values);

                var nsal = sal +( sal*(values /100));

                alert("Your new salary is - " + nsal);
            }

         salin();

https://jsfiddle.net/abdur_rehman26/7L9uvxon/

Comments

0

Try this instead:

function salin()
        {

                            var sal = prompt("Enter your current salary - ","");
            var income = prompt("Enter the increment % - ","");

            sal = parseInt(sal);
            income = parseInt(income);

            var nsal = sal +( sal*(income /100));

            return "Your new salary is - " + nsal;
        }

     alert(salin());

Notice I added return and put the alert() on the function call. I also changed "in" to "income"

1 Comment

Good answers don’t just dump “working” code. Good answers explain the OP’s mistake or how to approach the problem.
0

'in' is a reserved keyword. change that to some other variable name

       <body>

    <script language="javascript" type="text/javascript">
        function salin()
        {
            var sal = prompt("Enter your current salary - ","");
            var in1 = prompt("Enter the increment % - ","");

            sal = parseInt(sal);
            in1 = parseInt(in1);

            var nsal = sal +( sal*(in1 /100));

            alert("Your new salary is - " + nsal);
        }

     salin();
  </script>



</body>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.