Eval is returning Right-hand side of 'instanceof' is not an object

For the life of me I can not figure out where I have messed up with the below code. It works just fine when I run it in console but when I bring it into Nightbot I get “Right-hand side of ‘instanceof’ is not an object”. If anyone has any ideas I would greatly appreciate them.

$(eval 
var gameJson = $(urlfetch json https://api.myjson.com/bins/18t5d6);
var gameData = [];
var sortedData = [];
var printTxt = 'The Scores Are: \n';


for (var i in gameJson)
{
	gameData.push([gameJson[i], i])
}

sortedData = gameData.sort().reverse()

for (var x in sortedData)
{
	printTxt += (sortedData[x][1] + ': ' + sortedData[x][0] + '\n')
}

)

You don’t want to be using for...in in this context here’s what I came up with instead

const gameJson = $(urlfetch json https://api.myjson.com/bins/18t5d6);
const gameArr = Object.keys(gameJson).map(key => [key, gameJson[key]]);
gameArr.sort((a,b) => b[1] - a[1]);
`The Scores Are: ${gameArr.map(e => e.join(': ')).join(',')}`;

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.