FCC - JS Functions

by vanduzled

JavaScript

//We can pass values into a function with arguments. 
function timesFive(num){
  return num * 5;
}

//You can use a return statement to send a value back out of a function.
var answer = timesFive(5);
console.log(answer);
//25

// Setup
var processed = 0;

function processArg(num) {
  return (num + 3) / 5;
}

// Only change code below this line
processed = processArg(7);

console.log(processed);
//2


function nextInLine(arr, item) {
  // Only change code below this line
  arr.push(item);
  return arr.shift();
  // Only change code above this line
  

}

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

// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));

/* Before: [1,2,3,4,5]
1
After: [2,3,4,5,6] */




//Testing Objects for Properties
// https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties
function checkObj(obj, checkProp) {
  // Only change code below this line
  if(obj.hasOwnProperty(checkProp)){
    return obj[checkProp];
  }else {
    return "Not Found";
  }
  // Only change code above this line
}