QUICK UPDATE!
I may have fixed it. Now the code looks like this:
<script type="text/javascript">
function rangeAnswers() {
var answer = prompt ("How much do you like pizza?")
if (answer > 0 )
confirm("That's a bit low")
window.location="http://www.continue.com";
if (answer > 20 )
confirm("Quite a decent score, isn't it?")
window.location="http://www.continue.com";
}
</script>
And it works. At this point i think that if i put other if's at the end for <0 or > 100 i can prompt the error message and without linking to the page in that two little if's i stay on the page right?
First off let me tell you i just started with js so this may be a bit dumb.
Here's what i need to do. I have a normal HTML link with a function called on click which asks the user something like "How much do you like pizza(0 100)?".
The user types in a number and i want different answers, which will still direct you to the link anyway(so no controls to send back the user here) based on the number he wrote.
I want four major breakpoints at 0-25, 26-50, 51-75, 71-100 ELSE(lower or higher value) it just alerts("The number you specified is invalid") and stays in the page so the user can click again and put a correct value(nothing fancy then).
The thing i want when he inserts a correct value is let's say 0-25 "You don't like it very much", 26-50 "Not good but not bad" etcetera + the link.
Here's my HTML a:
<h2><a href="javascript:rangeAnswers();">Click here to tell us how much you like pizza and continue!</a></h2>
And here's the foundation of my Javascript function which is NOT loading! I tried a simple Ok/cancel prompt and it worked but i still can't get the logic of if/else statement. THIS IS THE OLD CODE, I RE-PASTED THE CORRECT ONE! function rangeAnswers() { var answer = prompt ("How much do you like pizza?") if (answer) > 0
{
alert= "That's a bit low"
window.location="http://www.continue.com";
} else
if (answer) > 20
{
alert= "You don't like it nor hate it"
window.location="http://www.continue.com";
} else
}
</script>
I think that's all for now, i'm still trying to work on this while i'm waiting for replies but it's been a while now and i can't get what i'm missing.
HERE'S THE UPDATED WORKING CODE
It doesn't load my alert/prompts though.
function rangeAnswers() {
var answer = prompt ("How much do you like pizza?")
if (answer > 0 )
alert= "Nice!"
window.location="http://www.continue.com";
if (answer > 20 )
alert= "Nice!"
window.location="http://www.continue.com";
}