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 trialorange sky
Front End Web Development Techdegree Student 4,945 PointsChallenge Task 1(andrew, greet, args1)
Hello,
What is wrong with this code? I am following instructions and my output is the intended output.
<!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: Call and Apply</h2>
<script>
var genericGreet = function(name, mood, emoticon) {
name = name || "you";
mood = mood || "good";
return "Hello " + name + ", my name is " + this.name +
" and I am in a " + mood + " mood!" + emoticon;
}
var andrew = {
name: "Andrew"
}
var args1 = ["Michael", "awesome", ":)"];
var greet = genericGreet;
console.log( greet.apply(andrew, args1));
</script>
</body>
</html>
2 Answers
Dino Paškvan
Courses Plus Student 44,108 PointsYou are doing things in the code beyond the scope of the task. You have changed the name of the variable (greeting
) that is supposed to hold the result of applying genericGreet
to andrew
.
There is no need for you to console.log
anything. Of course, you can use it while practicing, but the code challenge will check the content of a variable once the challenge is run.
The task says: Set the 'greeting' variable, on line 29, by using the 'genericGreet' function in the context of 'andrew' with the array of arguments, 'args1'.
The only change you have to do is on line 29, and you just have to expand the code there (without modifying it).
Use the apply
method on genericGreet
on that line and pass the same parameters that you've used and you will pass the code challenge.
orange sky
Front End Web Development Techdegree Student 4,945 PointsThanks Dino!! your explanations are so clear:)