Functions practice (Let/Return/console.log "Confusion")

I’m getting the answer right but comparing my code to the solutions, they’re often a little different. I guess I’m a little confused as to when I should just be using return, or defining things with let etc.

Example with divideByThree:

function divideByThree(num) {
let sum=(num)/3;
return sum;// your code here…
}

Solution:

function divideByThree(num) {
return num / 3;
}

And then with the next one (whisper) I just use return whilst this time the solution defines first with let.
Does it really matter?

Hello,

i had the same question a while back, and got some great feedback from a fellow student:

  • there are many ways to skin a cat :slight_smile: . As long as you solve the problem statement you are good to go.
  • think about efficiency here, sometimes solving a problem with least amount of lines is way to go.
  • think about readability of your code. if you have a function with numerous calculations, declaring a variable with “let” makes the code more readable and easier to understand. from the example, i know we are taking a num and returning sum - much more intuitive and easy to read.
1 Like