Advertisement
imjyb1008

Q2

Dec 8th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ans = Math.round(Math.random() * 100 + 1);
  2.            
  3. var max = 100;
  4. var min = 1;
  5.            
  6. while (true)
  7. {
  8.     x = (max+min)/2;
  9.                
  10.     if(x == ans)
  11.     {
  12.         break;
  13.     }
  14.     else if( x > ans )
  15.     {
  16.         max = x ;
  17.     }
  18.     else if( x < ans )
  19.     {
  20.         min = x ;
  21.     }
  22. }
  23.  
  24. document.write("Result :" +  x );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement