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 trialCamilla Westin
18,693 Pointsvue.js Computed property: Syntax error: Unexpected token this
I get the error "Uncaught SyntaxError: Unexpected token this" when trying to add my computed property. What have i missed?
<select v-on:change="filterType">
<option>Sort by type</option>
<option v-for="task in uniqueItemsList"> {{ task }}</option>
</select>
new Vue({
el: '#taskmanager',
data: {
tasks: tasks,
newName: '',
newDescription: '',
type: '',
error: false
},
methods: {
toggleTask: function(task){
task.opened = !task.opened;
},
addNew: function() {
if(!this.newName || !this.newDescription) {
this.error = true;
} else {
this.tasks.push({
name: this.newName,
description: this.newDescription,
opened: false
});
this.newName = '',
this.newDescription = '',
this.error = false
}
},
filterType: function() {
this.type = event.target.value;
}
},
computed: {
uniqueItemsList: function (){
const types = [];
this.tasks.forEach(task)=>{
if (!types.includes(task.type)){
types.push(task.type);
}
});
return types;
}
}
});
Mod Note - Added markdown to code for readability.
2 Answers
Adam N
70,280 PointsDouble check that your forEach method is being closed in the right spot.
One hint is: since you're passing an arrow func with one parameter to forEach, you can leave off the parenthesis around the parameter.
Let me know if this helps here
Camilla Westin
18,693 PointsCamilla Westin
18,693 PointsI'm afraid not :( I feel like I have watched this video a million times now :P How would it look if I left off the parenthesis around the parameter?
Camilla Westin
18,693 PointsCamilla Westin
18,693 PointsOk so I did this:
And it works! But was that what you were saying I should do?
Adam N
70,280 PointsAdam N
70,280 PointsMy route would've kept you using an arrow func. Your route does work, tho!
I was intending for you to edit the original code to make it look like this:
this.tasks.forEach(task=>{
The ) after task was closing your forEach at that point, which was too early for it to close.