Consider your function declaration. Does this work as a function yet? How would the program know it’s not an object? How would you pass a parameter in? for example: getClassId("Biology")
One distinguishing characteristic of functions in their parameters (), even when they’re empty, so if you’re declaring a function without them, it should raise alarm bells.
const getComputerChoice = {
const randomNumber = Math.floor(Math.random() * 3);
}
// will return error, it's not quite a function
// and it's not quite an object
Object declaration for comparison:
let getComputerChoice = {
randomNumber : Math.floor(Math.random() * 3)
}
console.log(getComputerChoice.randomNumber)
//outputs random number between 0-2
console.log(getComputerChoice)
// { randomNumber: 1 }
Function declaration with const:
const say_hi = function() {
return "hi";
}
console.log(say_hi());
//hi
console.log(say_hi);
//[Function: say_hi]
const say_something = function(something) {
return something;
}
console.log(say_something('hi'));
//hi
console.log(say_something);
//[Function: say_something]
One last thing of note, notice the difference in output when we take the parameters away from the declared objects and functions. It is useful to know, because objects are also very powerful tools. So it’s good to be able to verify that you’ve created the tool you want to create… even if at the moment it creates a similar output, it’s potential use will be inherently different.
console.log(getComputerChoice) // from my object declaration example
// { randomNumber: 1 }
console.log(say_hi);
//[Function: say_hi]
console.log(say_something);
//[Function: say_something]