Sign in with
Sign up | Sign in
Your question
Solved

Java code issues

Tags:
  • Java
  • Consoles
  • Speed
  • Systems
Last response: in Opinions and Experiences
Share
March 5, 2014 10:37:51 AM

Hello, my code is

  1. var speed = 65;
  2.  
  3. // Complete the condition in the ()s on line 4
  4. if (speed <= 80) {
  5. // Use console.log() to print "Slow downc
  6. console.log("Slow down")
  7. } else {
  8. // Use console.log() to print "Drive safe"
  9. console.log("Drive safe")
  10. }

But it keeps prompting "Slow down" instead. Am I misinterpreting the <= and > part? Thanks in advance.

<code tags added by administrator>

More about : java code issues

Best solution

March 5, 2014 11:24:59 AM

<= is less than or equal to. Since 65 is less than 80, it will do "Slow down." You have the sign reversed, you want >= at the if statement.
Share
March 5, 2014 11:31:48 AM

shoob0x said:
Hello, my code is

  1. var speed = 65;
  2.  
  3. // Complete the condition in the ()s on line 4
  4. if (speed <= 80) {
  5. // Use console.log() to print "Slow downc
  6. console.log("Slow down")
  7. } else {
  8. // Use console.log() to print "Drive safe"
  9. console.log("Drive safe")
  10. }

But it keeps prompting "Slow down" instead. Am I misinterpreting the <= and > part? Thanks in advance.

Please read this http://www.tomshardware.com/forum/244553-49-read-progra... before posting homework assignments. I've fixed your code this time, but next time please use the code tags.
m
0
l
Related resources
March 5, 2014 11:40:39 AM

navysealbrian said:
<= is less than or equal to. Since 65 is less than 80, it will do "Slow down." You have the sign reversed, you want >= at the if statement.


So in Java < 8 means less than 8? Such an odd langauage. Thank you though.
m
0
l
March 5, 2014 11:42:54 AM

shoob0x said:
navysealbrian said:
<= is less than or equal to. Since 65 is less than 80, it will do "Slow down." You have the sign reversed, you want >= at the if statement.


So in Java < 8 means less than 8? Such an odd langauage. Thank you though.


Means the same thing in all languages. Even in math.
m
0
l
March 5, 2014 11:47:54 AM

What's odd about < being less than? When you are doing something like x < 8, you are saying x is less than 8, just like if you were doing plain math. So if you have x = 20, and then make an if (x < 8) statement, the computer will evaluate if x is in fact less than (<) 8 in this example. 20 < 8 is false in the case, so the computer will skip to the next statement. The signs are exactly the same as they are used in mathematics.
m
0
l
March 5, 2014 12:02:35 PM

navysealbrian said:
What's odd about < being less than? When you are doing something like x < 8, you are saying x is less than 8, just like if you were doing plain math. So if you have x = 20, and then make an if (x < 8) statement, the computer will evaluate if x is in fact less than (<) 8 in this example. 20 < 8 is false in the case, so the computer will skip to the next statement. The signs are exactly the same as they are used in mathematics.


Wait, dear god I'm tired xD thank you.
m
0
l
March 5, 2014 12:10:19 PM

ex_bubblehead said:
shoob0x said:
navysealbrian said:
<= is less than or equal to. Since 65 is less than 80, it will do "Slow down." You have the sign reversed, you want >= at the if statement.


So in Java < 8 means less than 8? Such an odd langauage. Thank you though.


Means the same thing in all languages. Even in math.


Yes xD forgive me, I'm quite tired.
m
0
l
!