Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Array Iteration Methods Array Manipulation Practice reduce()

Function syntax help using reduce method

My error says I have an unexpected token of a curly brace, and I'm unsure how my syntax is wrong. The goal is to return a count of the number of phone numbers that begin with the (503) area code. Another set of eyes on this would be very helpful. Thanks.

app.js
const phoneNumbers = ["(503) 123-4567", "(646) 123-4567", "(503) 987-6543", "(503) 234-5678", "(212) 123-4567", "(416) 123-4567"];
let numberOf503;

// numberOf503 should be: 3
// Write your code below

numberOf503 = phoneNumbers.reduce((count, phoneNum) => {
  if (phoneNum.startsWith('(503)') {
     return count + 1 
     }
     return count
}, 0)

console.log(numberOf503)

2 Answers

Realized i needed another parens on line 9.

Dustin U
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Dustin U
Treehouse Teacher

Hey Michelle 👋🏼 Looks like a quick fix! Where your if statement starts, you're opening a parenthesis for the condition but you're not closing it. if ( phoneNum.startsWIth() {}

You're opening and closing the parenthesis for the startsWIth() method, but not the initial if statement!