-2

I am new to javascript, please help me with this code, where did I get it wrong?

function magix2(arrangment, figures) {
    arrangment.push(figures);
    return arrangment.shift();
}

var bum = [26,27,28,29,30,31,32];

console.log("Before: " + JSON.stringify(arrangment));
console.log(magix2(bum, 33));
console.log("After: " + JSON.stringify(arrangment));
Teemu
  • 22,918
  • 7
  • 53
  • 106

3 Answers3

0
function magix2(arrangment, figures) {
  arrangment.push(figures);
  return arrangment.shift();
}

var bum = [26,27,28,29,30,31,32];

//console.log("Before: " + JSON.stringify(arrangment));

console.log(magix2(bum, 33));

//console.log("After: " + JSON.stringify(arrangment));

arrangment is the argument of function, you can't access that argument outside the function, that's I commented out these console lines.

Muhammad Bilal
  • 1,840
  • 1
  • 18
  • 16
0

arrangment is an argument of magix2 function you can not access it outside. Try accessing bum instead.

function magix2(arrangment, figures) {
    arrangment.push(figures);
    return arrangment.shift();
}

var bum = [26,27,28,29,30,31,32];

console.log("Before: " + JSON.stringify(bum));
console.log(magix2(bum, 33));
console.log("After: " + JSON.stringify(bum));
Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24
0

The correct way to perform your operation. Console Return 26, as it is first element, also 33 is added to list The correct way to perform your operation. Console Return 26, as it is first element, also 33 is added to list

Raman Kumar
  • 53
  • 1
  • 1
  • 5