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 trialMUZ140252 Prudence Khupe
8,921 Pointsmethods
help me out with this code
<!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 = function() {
return "Hello, my name is " + this.name;
}
var ryan = {
name: "Ryan",
greet: andrew.greet();
}
</script>
</body>
</html>
3 Answers
Hugo Paz
15,622 PointsHi there,
You need to use the function genericGreet inside your objects. You create a new property called greet and assign it the genericGreet variable value, which is a function.
var andrew = {
name: "Andrew",
greet: genericGreet
}
var ryan = {
name: "Ryan",
greet: genericGreet
}
MUZ140252 Prudence Khupe
8,921 Pointsim still getting There was an error with your code: SyntaxError: Parse error
Hugo Paz
15,622 PointsDid you replace the 2 original variables with the code above?
Can you please post the code you tried?
MUZ140252 Prudence Khupe
8,921 Pointsok i noticed whr i had gone wrong. had put a semicolon lyk this, greet: genericGreet;