# Ticket Time explainer

Aim of the puzzle: Find the key information in a word problem and solve the problem using code.
Walk through of solution: Ayah needs to figure out how many students in her class will need an adult ticket for their trip to the museum. The museum states that all visitors older than 12 must have an adult ticket.

In this puzzle, the `studentList` is imported from additional code. It contains an array of objects, each with a `name` and `age` property.

The function will need to be called with the `studentList`, so to start, add a parameter to the `needsAdultTicket()` function, for example, `needsAdultTicket(list)`.

Then, inside the function, add a for loop to iterate through the parameter. Then, add an if statement that checks if the `age` property of each item in the array is greater than 12.

Inside the if statement, use `console.log()` to print the `name` property of the students who are older than 12.

Finally, call the function with `studentList` as an argument.
Sample code solution:

``````import { studentList } from 'class.students';

for (var element of list) {
if (element['age'] > 12) {
console.log(element['name']);
}
}
}

``````

Additional Code (hidden code that runs before the puzzleās code):

``````let studentList = [
{name:'Amelia',     age: 13},
{name:'Anna' ,      age: 12},
{name:'Charlotte',  age: 13},
{name:'Claudia',    age: 13},
{name:'Clyde',      age: 13},
{name:'Emily',      age: 12},
{name:'Jack',       age: 12},
{name:'Kyle',       age: 13},
{name:'Marcus',     age: 13},
{name:'Rachel',     age: 12},
{name:'Tony',       age: 12},
];
``````
11 Likes

What am I doing wrong?

2 Likes

Still cant change āforā statement from āvarā to ālist.ā Any suggestions?

Hey there,

The first part of a for loop (the `var element`) sets up a temporary looping variable that represents the current item each time it loops. The `of studentList` tells the for loop what to loop through.

This means you donāt have to change the 1st part of the for loop when you add it to the code in Grasshopper. The `var element` that is automatically added to the code is fine as is. You just need to change the 2nd part so the loop knows what to iterate through.

Hope this helps!
Ben

Hi, Iām still stuck in here. My code looks working fine. I donāt know why I am told my coding is wrong. Please check my attached coding.

1 Like

Hey there,

It looks like this issue is that the function call is inside a `console.log()`. This means the puzzleās completion logic isnāt finding the function call, which is why youāre seeing a message indicating that the function call doesnāt exist.

Try taking the function call out of the `console.log()`, and the puzzle should complete.

Hope this helps!
Ben

5 Likes
2 Likes

Hey there, it looks like the `['name']` is outside the `console.log()` statement.

Try changing:

``````console.log(element)['name']
``````

to

``````console.log(element['name'])
``````

Hope this helps!
Ben

5 Likes

Iām not sure what Iām doing wrong. Please help! Iāve tried the function and calling it but I cant figure out what I need to fix.

2 Likes

Hey there, the puzzleās completion trigger is looking for the function call `needsAdultTicket(studentList)`, but canāt see it because the call is inside a `console.log()`.

Try changing `console.log(needsAdultTicket(studentList))` to just `needsAdultTicket(studentList)`.

That should solve the problem! Let me know if you have any questions.
Ben

4 Likes

Focusā¦ Is reading and comprehensionā¦

3 Likes

I know you need to feed a parameter into the function to use the imported studentList array into the function, but itās never mentioned in the instructions making it look like all the code needs to be done within the function.

Maybe addressing this in the instructions would make this more clearer for others?

4 Likes

Hey there, great feedback!

Thanks,
Ben

Hey! Iām stuck in here, can You help me out please?

2 Likes

Hey there, in your if statement, change `element['age' > 12]` to `element['age'] > 12`.

Hope this helps!
Ben

3 Likes

Already reviewed the forā¦ of loop lesson, but I still donāt understand why it keeps telling me to make it loop through the list.

1 Like

Hey there, looks like there are a few small issues:

`list` is the parameter of the function. You want to use this inside the function, so change your for loop to loop through `list` instead of `studentList`, like this:

``````for (var element of list)
``````

Then, outside the function, call the function with `studentList`, like this:

``````console.log(needsAdultTicket(studentList))
``````

Finally, in the code block of the for loop, youāre printing a string with the text `'name'`, rather than `element['name']`. Try changing it to this:

``````console.log(element['name'])
``````

Hope this helps!
Ben

1 Like

It did, thanks.

I wish there was an easier way to find the needed lessons by topic, instead of going through the whole list of exercises trying to find the right one. We could all go back and review first, then bug you if we could definitely not find the solution.

Thank you again for your time and patience.

1 Like