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>
4 Answers 4
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
Comments
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();
Comments
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
'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>
inis reserved keyword in java-script so, your variable name cannot beinSyntaxError: missing variable name.