Sampsa
Sampsa

Reputation: 711

Function return value to variable

I am having trouble assigning function return value to variable. Why do I get the function returned instead of the final product when I log it to console?

time = ->
  today = new Date()
  minutes = today.getMinutes()
  if minutes < 10 then minutes = "0#{minutes}"
  hours = today.getHours()
  if hours < 10 then hours = "0#{hours}"
  "#{hours}:#{minutes}"
console.log time

Upvotes: 1

Views: 111

Answers (1)

Niko
Niko

Reputation: 26730

Simply add do to execute the function (if you expect "time" to contain the string, not the function):

time = do ->

or use "time" as a function, i.e., invoke it:

console.log time()

Upvotes: 5

Related Questions