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 Foundations Objects Methods

Need help with this challenge

I don't know why this is not working. I followed the direction and yet is till not working. I keep getting parse error. The question is on 'andrew' and 'ryan' set the 'greet' method as the 'genericGreet' function.

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title> JavaScript Foundations: Objects</title>
    <style>
      html {
        background: #FAFAFA;
        font-family: sans-serif;
      }
    </style>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Objects: Methods</h2>
    <script>


      var genericGreet = function() {
        return "Hello, my name is " + this.name;
      }

      var andrew = {
        name: "Andrew"
        greet:genericGreet
      }

      var ryan = {
        name: "Ryan"
        greet:genericGreet
      }

    </script>
  </body>
</html>

3 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello layeesolo,

I think you just forgot commas after "Andrew" and after "Ryan"..

;)

Let me know if that sorts it out, otherwise I will have a deeper look.

Vittorio

Colin Bell
Colin Bell
29,679 Points

You need to set the greet key to a value of genericGreet for both andrew and ryan:

    <script>
     genericGreet = function() {
        return "Hello, my name is " + this.name;
      }

      var andrew = {
        name: "Andrew",
        greet: genericGreet
      }

      var ryan = {
        name: "Ryan",
        greet: genericGreet
      }
    </script>

Edit: Looks like you did that. But you forgot to add the comma between sets of key:values. You need a comma between each set both "Andrew" and "Ryan"

my code is the same as your. I don't know why is not working

Colin Bell
Colin Bell
29,679 Points

Sorry. I edited it. You're just forgetting the commas.