Is there a way to force JavaScript to return a negative value in an alert box?
up vote
7
down vote
favorite
JavaScript is returning X - Y , where X and Y are Real numbers and their sum is negative, instead of just the negative sum.
I've tried an if else statement using
if (Math.sign(function)<0)
else
where the if statement just had a "-" in front of the value to concatenate the string "minus" character in front of the number and the else statement was just a regular print out
function velocity_final(initial_velocity, acceleration, time)
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = initial_velocity + acceleration * time;
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
javascript
New contributor
add a comment |
up vote
7
down vote
favorite
JavaScript is returning X - Y , where X and Y are Real numbers and their sum is negative, instead of just the negative sum.
I've tried an if else statement using
if (Math.sign(function)<0)
else
where the if statement just had a "-" in front of the value to concatenate the string "minus" character in front of the number and the else statement was just a regular print out
function velocity_final(initial_velocity, acceleration, time)
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = initial_velocity + acceleration * time;
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
javascript
New contributor
for the prompts I put in 32, -9.81, 10 and it returns 32-98.100000 instead of just a negative number
– Evan Howington
1 hour ago
1
Please do take the time to format your sample code and you do not have to follow up content on a comment, edit the post instead. You get unlimited edits on your post so feel free to use as much as you want.
– Abana Clara
1 hour ago
add a comment |
up vote
7
down vote
favorite
up vote
7
down vote
favorite
JavaScript is returning X - Y , where X and Y are Real numbers and their sum is negative, instead of just the negative sum.
I've tried an if else statement using
if (Math.sign(function)<0)
else
where the if statement just had a "-" in front of the value to concatenate the string "minus" character in front of the number and the else statement was just a regular print out
function velocity_final(initial_velocity, acceleration, time)
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = initial_velocity + acceleration * time;
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
javascript
New contributor
JavaScript is returning X - Y , where X and Y are Real numbers and their sum is negative, instead of just the negative sum.
I've tried an if else statement using
if (Math.sign(function)<0)
else
where the if statement just had a "-" in front of the value to concatenate the string "minus" character in front of the number and the else statement was just a regular print out
function velocity_final(initial_velocity, acceleration, time)
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = initial_velocity + acceleration * time;
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
javascript
javascript
New contributor
New contributor
edited 43 mins ago
Alexander O'Mara
42.9k1395128
42.9k1395128
New contributor
asked 1 hour ago
Evan Howington
384
384
New contributor
New contributor
for the prompts I put in 32, -9.81, 10 and it returns 32-98.100000 instead of just a negative number
– Evan Howington
1 hour ago
1
Please do take the time to format your sample code and you do not have to follow up content on a comment, edit the post instead. You get unlimited edits on your post so feel free to use as much as you want.
– Abana Clara
1 hour ago
add a comment |
for the prompts I put in 32, -9.81, 10 and it returns 32-98.100000 instead of just a negative number
– Evan Howington
1 hour ago
1
Please do take the time to format your sample code and you do not have to follow up content on a comment, edit the post instead. You get unlimited edits on your post so feel free to use as much as you want.
– Abana Clara
1 hour ago
for the prompts I put in 32, -9.81, 10 and it returns 32-98.100000 instead of just a negative number
– Evan Howington
1 hour ago
for the prompts I put in 32, -9.81, 10 and it returns 32-98.100000 instead of just a negative number
– Evan Howington
1 hour ago
1
1
Please do take the time to format your sample code and you do not have to follow up content on a comment, edit the post instead. You get unlimited edits on your post so feel free to use as much as you want.
– Abana Clara
1 hour ago
Please do take the time to format your sample code and you do not have to follow up content on a comment, edit the post instead. You get unlimited edits on your post so feel free to use as much as you want.
– Abana Clara
1 hour ago
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
Prompt returns a string. Such that doing "1" +"-1"
will result to "1-1"
due to concatenation. Why "1" + "1"
becomes 2
in the printed output is because of how Javascript automatically attempts to parse strings into numbers, if the evaluated strings contains a character, it gets concatenated instead. You need to explicitly cast the numbers.
You can use Number()
, you can multiply each string to 1 to automatically convert them, you can use parseInt()
, or you can use +
preceding the returned values as shown by the other answers here. I would use the first one I mentioned in the example below.
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = Number(initial_velocity) + Number(acceleration) * Number(time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
velocity_final();
All good answers. Thank you for showing the Number part in the code. I had changed it to initial_velocity - ((-1)*acceleration*time) and that worked.. I changed to that because one of my other equations is almost identical except it utilizes subtraction and there were no issues. Previously I was just performing multiplication and division so this did not arise. I am converting my code from Python to JS, so I am learning on the fly. Thank you very much!
– Evan Howington
41 mins ago
add a comment |
up vote
6
down vote
prompt
always returns a string, not a number. Even if the person enters a number, it will be a string that represents that number, not a number itself.
You will need to cast the results of prompt
to a number before you can preform addition on it. When used with string, +
is the concatenation operator, rather then the addition operator.
Somewhat confusingly, you can actually use an unary +
for this purpose.
var initial_velocity = +prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = +prompt('Please enter the acceleration in Meters per Second Squared');
var time = +prompt('Please enter the time in seconds');
var final_velocity = initial_velocity + acceleration * time;
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
add a comment |
up vote
1
down vote
The +
operator can be both addition and string concatenation. When the prompt
box returns, it gives you back a string. String + number = string
, so it concatenates (joins) the two values together instead of adding them. To fix this, you can convert the string to a number using a single +
operator (and some parentheses if you want) to convert the string to a number, like so:
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = (+initial_velocity) + (+acceleration) * (+time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
console.log(velocity_final());
You could also convert the values as soon as the prompt returns a value, if you wanted.
PS: I removed the function parameters, as you set them manually anyways rather than passing anything in. If you do end up passing in values later rather than asking the user for them, you'll need to add those back into the function statement for them to be properly passed in.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Evan Howington is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53862185%2fis-there-a-way-to-force-javascript-to-return-a-negative-value-in-an-alert-box%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Prompt returns a string. Such that doing "1" +"-1"
will result to "1-1"
due to concatenation. Why "1" + "1"
becomes 2
in the printed output is because of how Javascript automatically attempts to parse strings into numbers, if the evaluated strings contains a character, it gets concatenated instead. You need to explicitly cast the numbers.
You can use Number()
, you can multiply each string to 1 to automatically convert them, you can use parseInt()
, or you can use +
preceding the returned values as shown by the other answers here. I would use the first one I mentioned in the example below.
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = Number(initial_velocity) + Number(acceleration) * Number(time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
velocity_final();
All good answers. Thank you for showing the Number part in the code. I had changed it to initial_velocity - ((-1)*acceleration*time) and that worked.. I changed to that because one of my other equations is almost identical except it utilizes subtraction and there were no issues. Previously I was just performing multiplication and division so this did not arise. I am converting my code from Python to JS, so I am learning on the fly. Thank you very much!
– Evan Howington
41 mins ago
add a comment |
up vote
2
down vote
accepted
Prompt returns a string. Such that doing "1" +"-1"
will result to "1-1"
due to concatenation. Why "1" + "1"
becomes 2
in the printed output is because of how Javascript automatically attempts to parse strings into numbers, if the evaluated strings contains a character, it gets concatenated instead. You need to explicitly cast the numbers.
You can use Number()
, you can multiply each string to 1 to automatically convert them, you can use parseInt()
, or you can use +
preceding the returned values as shown by the other answers here. I would use the first one I mentioned in the example below.
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = Number(initial_velocity) + Number(acceleration) * Number(time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
velocity_final();
All good answers. Thank you for showing the Number part in the code. I had changed it to initial_velocity - ((-1)*acceleration*time) and that worked.. I changed to that because one of my other equations is almost identical except it utilizes subtraction and there were no issues. Previously I was just performing multiplication and division so this did not arise. I am converting my code from Python to JS, so I am learning on the fly. Thank you very much!
– Evan Howington
41 mins ago
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Prompt returns a string. Such that doing "1" +"-1"
will result to "1-1"
due to concatenation. Why "1" + "1"
becomes 2
in the printed output is because of how Javascript automatically attempts to parse strings into numbers, if the evaluated strings contains a character, it gets concatenated instead. You need to explicitly cast the numbers.
You can use Number()
, you can multiply each string to 1 to automatically convert them, you can use parseInt()
, or you can use +
preceding the returned values as shown by the other answers here. I would use the first one I mentioned in the example below.
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = Number(initial_velocity) + Number(acceleration) * Number(time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
velocity_final();
Prompt returns a string. Such that doing "1" +"-1"
will result to "1-1"
due to concatenation. Why "1" + "1"
becomes 2
in the printed output is because of how Javascript automatically attempts to parse strings into numbers, if the evaluated strings contains a character, it gets concatenated instead. You need to explicitly cast the numbers.
You can use Number()
, you can multiply each string to 1 to automatically convert them, you can use parseInt()
, or you can use +
preceding the returned values as shown by the other answers here. I would use the first one I mentioned in the example below.
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = Number(initial_velocity) + Number(acceleration) * Number(time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
velocity_final();
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = Number(initial_velocity) + Number(acceleration) * Number(time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
velocity_final();
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = Number(initial_velocity) + Number(acceleration) * Number(time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
velocity_final();
edited 39 mins ago
answered 1 hour ago
Abana Clara
1,487719
1,487719
All good answers. Thank you for showing the Number part in the code. I had changed it to initial_velocity - ((-1)*acceleration*time) and that worked.. I changed to that because one of my other equations is almost identical except it utilizes subtraction and there were no issues. Previously I was just performing multiplication and division so this did not arise. I am converting my code from Python to JS, so I am learning on the fly. Thank you very much!
– Evan Howington
41 mins ago
add a comment |
All good answers. Thank you for showing the Number part in the code. I had changed it to initial_velocity - ((-1)*acceleration*time) and that worked.. I changed to that because one of my other equations is almost identical except it utilizes subtraction and there were no issues. Previously I was just performing multiplication and division so this did not arise. I am converting my code from Python to JS, so I am learning on the fly. Thank you very much!
– Evan Howington
41 mins ago
All good answers. Thank you for showing the Number part in the code. I had changed it to initial_velocity - ((-1)*acceleration*time) and that worked.. I changed to that because one of my other equations is almost identical except it utilizes subtraction and there were no issues. Previously I was just performing multiplication and division so this did not arise. I am converting my code from Python to JS, so I am learning on the fly. Thank you very much!
– Evan Howington
41 mins ago
All good answers. Thank you for showing the Number part in the code. I had changed it to initial_velocity - ((-1)*acceleration*time) and that worked.. I changed to that because one of my other equations is almost identical except it utilizes subtraction and there were no issues. Previously I was just performing multiplication and division so this did not arise. I am converting my code from Python to JS, so I am learning on the fly. Thank you very much!
– Evan Howington
41 mins ago
add a comment |
up vote
6
down vote
prompt
always returns a string, not a number. Even if the person enters a number, it will be a string that represents that number, not a number itself.
You will need to cast the results of prompt
to a number before you can preform addition on it. When used with string, +
is the concatenation operator, rather then the addition operator.
Somewhat confusingly, you can actually use an unary +
for this purpose.
var initial_velocity = +prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = +prompt('Please enter the acceleration in Meters per Second Squared');
var time = +prompt('Please enter the time in seconds');
var final_velocity = initial_velocity + acceleration * time;
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
add a comment |
up vote
6
down vote
prompt
always returns a string, not a number. Even if the person enters a number, it will be a string that represents that number, not a number itself.
You will need to cast the results of prompt
to a number before you can preform addition on it. When used with string, +
is the concatenation operator, rather then the addition operator.
Somewhat confusingly, you can actually use an unary +
for this purpose.
var initial_velocity = +prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = +prompt('Please enter the acceleration in Meters per Second Squared');
var time = +prompt('Please enter the time in seconds');
var final_velocity = initial_velocity + acceleration * time;
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
add a comment |
up vote
6
down vote
up vote
6
down vote
prompt
always returns a string, not a number. Even if the person enters a number, it will be a string that represents that number, not a number itself.
You will need to cast the results of prompt
to a number before you can preform addition on it. When used with string, +
is the concatenation operator, rather then the addition operator.
Somewhat confusingly, you can actually use an unary +
for this purpose.
var initial_velocity = +prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = +prompt('Please enter the acceleration in Meters per Second Squared');
var time = +prompt('Please enter the time in seconds');
var final_velocity = initial_velocity + acceleration * time;
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
prompt
always returns a string, not a number. Even if the person enters a number, it will be a string that represents that number, not a number itself.
You will need to cast the results of prompt
to a number before you can preform addition on it. When used with string, +
is the concatenation operator, rather then the addition operator.
Somewhat confusingly, you can actually use an unary +
for this purpose.
var initial_velocity = +prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = +prompt('Please enter the acceleration in Meters per Second Squared');
var time = +prompt('Please enter the time in seconds');
var final_velocity = initial_velocity + acceleration * time;
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
edited 44 mins ago
answered 1 hour ago
Alexander O'Mara
42.9k1395128
42.9k1395128
add a comment |
add a comment |
up vote
1
down vote
The +
operator can be both addition and string concatenation. When the prompt
box returns, it gives you back a string. String + number = string
, so it concatenates (joins) the two values together instead of adding them. To fix this, you can convert the string to a number using a single +
operator (and some parentheses if you want) to convert the string to a number, like so:
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = (+initial_velocity) + (+acceleration) * (+time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
console.log(velocity_final());
You could also convert the values as soon as the prompt returns a value, if you wanted.
PS: I removed the function parameters, as you set them manually anyways rather than passing anything in. If you do end up passing in values later rather than asking the user for them, you'll need to add those back into the function statement for them to be properly passed in.
add a comment |
up vote
1
down vote
The +
operator can be both addition and string concatenation. When the prompt
box returns, it gives you back a string. String + number = string
, so it concatenates (joins) the two values together instead of adding them. To fix this, you can convert the string to a number using a single +
operator (and some parentheses if you want) to convert the string to a number, like so:
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = (+initial_velocity) + (+acceleration) * (+time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
console.log(velocity_final());
You could also convert the values as soon as the prompt returns a value, if you wanted.
PS: I removed the function parameters, as you set them manually anyways rather than passing anything in. If you do end up passing in values later rather than asking the user for them, you'll need to add those back into the function statement for them to be properly passed in.
add a comment |
up vote
1
down vote
up vote
1
down vote
The +
operator can be both addition and string concatenation. When the prompt
box returns, it gives you back a string. String + number = string
, so it concatenates (joins) the two values together instead of adding them. To fix this, you can convert the string to a number using a single +
operator (and some parentheses if you want) to convert the string to a number, like so:
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = (+initial_velocity) + (+acceleration) * (+time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
console.log(velocity_final());
You could also convert the values as soon as the prompt returns a value, if you wanted.
PS: I removed the function parameters, as you set them manually anyways rather than passing anything in. If you do end up passing in values later rather than asking the user for them, you'll need to add those back into the function statement for them to be properly passed in.
The +
operator can be both addition and string concatenation. When the prompt
box returns, it gives you back a string. String + number = string
, so it concatenates (joins) the two values together instead of adding them. To fix this, you can convert the string to a number using a single +
operator (and some parentheses if you want) to convert the string to a number, like so:
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = (+initial_velocity) + (+acceleration) * (+time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
console.log(velocity_final());
You could also convert the values as soon as the prompt returns a value, if you wanted.
PS: I removed the function parameters, as you set them manually anyways rather than passing anything in. If you do end up passing in values later rather than asking the user for them, you'll need to add those back into the function statement for them to be properly passed in.
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = (+initial_velocity) + (+acceleration) * (+time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
console.log(velocity_final());
function velocity_final()
{
var initial_velocity = prompt('Please enter the Initial Velocity in Meters per Second');
var acceleration = prompt('Please enter the acceleration in Meters per Second Squared');
var time = prompt('Please enter the time in seconds');
var final_velocity = (+initial_velocity) + (+acceleration) * (+time);
alert('The Final Velocity is '+ final_velocity + ' Meters Per Second');
}
console.log(velocity_final());
answered 1 hour ago
Feathercrown
1,61611021
1,61611021
add a comment |
add a comment |
Evan Howington is a new contributor. Be nice, and check out our Code of Conduct.
Evan Howington is a new contributor. Be nice, and check out our Code of Conduct.
Evan Howington is a new contributor. Be nice, and check out our Code of Conduct.
Evan Howington is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53862185%2fis-there-a-way-to-force-javascript-to-return-a-negative-value-in-an-alert-box%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
for the prompts I put in 32, -9.81, 10 and it returns 32-98.100000 instead of just a negative number
– Evan Howington
1 hour ago
1
Please do take the time to format your sample code and you do not have to follow up content on a comment, edit the post instead. You get unlimited edits on your post so feel free to use as much as you want.
– Abana Clara
1 hour ago