if statement to compare string value with number - Javascript String Operation

Javascript examples for String Operation:String Compare

Description

if statement to compare string value with number

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//from  w w w  .  j a  v  a2  s .  c o  m
var inventory = "10";
if( inventory == "Sold Out" ){
   document.write("<b>Sold Out</b>");
}else if( inventory >= 6 ){
   document.write("<b>more than 5</b>");
}else if( inventory <= 5 ){
   document.write("<b>running low</b>");
}else{
  document.write("<b>error</b>");
}
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials