1

Problem
I have tried looking at the other solutions here but nothing is seeming to work for me. My problem is that I'm getting an unexpected var token on line 43, but I can't find any unclosed brackets or parentheses. I've tried deleting line by line, but the problem only starts on that line. If I delete line 43 the line above it has an unexpected ")" token and I can't figure that one out either. This is the code

CODE

// FUNCTION DEFINITION(S)
function map(array, callbackFunction) {
  var newArray = [];

  for (var i = 0; i < array.length; i++) {
    newArray = newArray + callbackFunction(element);
  }

  return newArray;
}

function cubeAll(numbers) {
  return map(numbers, function(n) {
    return n * n * n;
  });
}

// ASSERTION FUNCTION(S) TO BE USED
function assertArraysEqual (actual, expected, testName) {

  var allValuesAreEqual = true

  for (x = 0; x < actual.length; x++) {
    var actualValues = actual[x];
    var expectedValues = expected[x];
    if (actualvalues !== expectedValues) {
      allValuesAreEqual = false
      break;
    }
  }
  if (allValuesAreEqual === true) {
    console.log('passed')
  } else {
    console.log ('FAILED [' + testName + '] expected ' + expected + ', but got ' + actual + '.')
  }
}

// TESTS CASES
var numbers = [2, 3, 4];
var output = function cubeAll(numbers)
var actual = function map(output, cubeAll)

2
  • 1
    Which one is line 43? Commented Mar 5, 2020 at 21:06
  • 2
    Wait, var output = function cubeAll(numbers)? That's not how you call a function, it's just var output = cubeAll(numbers) Commented Mar 5, 2020 at 21:08

1 Answer 1

2

It looks like you're trying to run functions in your test cases, but you're using the function keyword, which defines functions.

function keyword expects a function definition (e.g. {somecode()}) before the next statement, but instead of finding a {, it finds the keyword var on the next line.

Solution

var output = cubeAll(numbers)
var actual = map(output, cubeAll)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I knew it had to be something simple, but I was just not seeing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.