Stand in Line Random Question

Stand in Line Random Question
0

#1

Tell us what’s happening:

So, this is a random question that seems really dumb asking but I think it will help be further understand functions.

Do all functions require a variable?

Your code so far

function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  var removed = arr.shift();
  return removed; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:


#2

By variable, do you mean parameter such as arr and item are parameters of the nextInLine function?

If that is what you mean, then the answer is no. The following is a function without parameters:

function noParameterFunction() {
  console.log("no parameters here, but let's still return something");
  return "hello";
}
noParameterFunction(); 
/* the above call executes the function and
 displays "no parameters here, but let's still return something" to the console 
and returns the string "hello" */

#3

Like,
var randomVar = someRandomThing.

Just wondering if all functions needed a variable defined inside of them for it to be a function.

I’m not sure if I explain that correctly but that’s the closest I can get to explaining what I mean.


#4

OK, I understand your question now. The answer is still no. The following function does not use variables or parameters.

function noVarsAndNoParametersFunction() {
  console.log("no variables or parameters inside this function");
}
noVarsAndNoParametersFunction(); 
/* the above call executes the function and
 displays "no variables or parameters inside this function" to the console */

I will note there is a limit to what you can achieve without variables. Plus, a variable name explaining what kind of value the variable holds makes your code much more readable by other programmers who may have to review your code at some point.