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
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 = 6if (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=0let gas=5console.log ("yuh gotta wait a little")}- console.log(checkDistance(3));