Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Unexpected token '||'

java script

Best Answer PuddingEatsPanda, 20 March 2016 - 07:27 PM

But your code:

if ($("txtCents").value < 0) || ($("txtCents").value > 99)

has an if statement that does not enclose the items that it is testing in a parenthesis. Have you tried:

if(($("txtCents").value < 0) || ($("txtCents").value > 99))
Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 orestos

orestos

    CC Newcomer

  • Member
  • PipPip
  • 12 posts

Posted 20 March 2016 - 12:09 PM

Hello Guys!

 

Following code works by i'm trying to make it more efficient by applying conditional statement instead of IF statements per each condition. I'm trying to do something like this: if ($("txtCents").value < 0) || ($("txtCents").value > 99) but debugger gives me an Unexpected token '||'. Please help. Thank you

 

EXAMPLE OF WORKING CODE TO BE OPTIMIZED 

 

cents = $("txtCents").value;

 
  if ($("txtCents").value=="") {
EnterValidIntMsg();
return;
}     
  if ($("txtCents").value < 0) {
EnterValidIntMsg();
return;
}
  if ($("txtCents").value > 99)  {
EnterValidIntMsg();
return;
}
  if (isNaN($("txtCents").value) ) {
alert("This is not a number, please enter a valid integer from 0 to 99");
return;
}    
 
  else  {  }


#2 PuddingEatsPanda

PuddingEatsPanda

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts

Posted 20 March 2016 - 07:27 PM   Best Answer

But your code:

if ($("txtCents").value < 0) || ($("txtCents").value > 99)

has an if statement that does not enclose the items that it is testing in a parenthesis. Have you tried:

if(($("txtCents").value < 0) || ($("txtCents").value > 99))

Edited by PuddingEatsPanda, 21 March 2016 - 03:30 PM.

Want to learn MOAR


#3 orestos

orestos

    CC Newcomer

  • Member
  • PipPip
  • 12 posts

Posted 22 March 2016 - 03:07 PM

It worked. Thanks a lot!



#4 PuddingEatsPanda

PuddingEatsPanda

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts

Posted 23 March 2016 - 05:39 PM

It worked. Thanks a lot!

You're welcome!


Want to learn MOAR