Ad

distance = 6<3?console.log("ALMOST THERE!"):console.log("yuh gotta wait a little");

console.log(...) doesn’t return a value — it prints and returns undefined.
So your ternary is really just running one console.log

Code
Diff
  • const msg = 6 < 3 ? "ALMOST THERE!" : "yuh gotta wait a little";
    console.log(msg);
    
    
    • distance = 6<3?console.log("ALMOST THERE!"):console.log("yuh gotta wait a little");
    • const msg = 6 < 3 ? "ALMOST THERE!" : "yuh gotta wait a little";
    • console.log(msg);
Code
Diff
  • function checkDistance(distance) {
      if (distance < 3) return 'ALMOST THERE';
      if (distance > 3) return 'yuh gotta wait a little';
      return 'you are exactly there!';
    }
    
    console.log(checkDistance(3));
    • let distance = 6
    • if (distance < 3) {
    • console.log ("ALMOST THERE!")
    • function checkDistance(distance) {
    • if (distance < 3) return 'ALMOST THERE';
    • if (distance > 3) return 'yuh gotta wait a little';
    • return 'you are exactly there!';
    • }
    • if (distance > 3) {
    • let brake=0
    • let gas=5
    • console.log ("yuh gotta wait a little")
    • }
    • console.log(checkDistance(3));