Won't Work! Lambda School Precourse: JS Assignment 12: Methods, Loops and the `this` Keyword
Cwill14 (13)

For this assignment, I can't figure out this second exercise.

function exerciseOne(){
  // Exercise One: In this exercise you are given an object called 'mathHelpers'
  // Within mathHelpers, create a method called 'double'
  // This method should take one parameter, a number, 
  // and it should return that number multiplied by two.
  let mathHelpers = {
    // Create double method in here.
    double: function(number){
    	return number * 2;
    }
  };
  return mathHelpers;
}

function exerciseTwo(userObj){
// Exercise Two: You will be given an object called 'userObj'
// userObject will already have a key on it called 'name'
// Add a method to userObj, called 'greeting'.
// Using the keyword 'this', the greeting method should return the following string:
// 'Hi, my name is ' and the users name.
// eg: If userObj has a name: 'Dan', greeting should return: Hi, my name is Dan'
// NOTE: DO NOT create a new object.
// NOTE: DO NOT create a key called name the key is already on the object.
	
  // Please write all of your code on the lines above.
  return userObj;
}

I feel the answer should be this:

greeting: function() {
		return "Hi, my name is " + this.name;
	}

I feel like this should work, but I keep getting the warnings:
label 'greeting' on function statement. and Missing name in function declaration. After running the tests, I get these:

Exercise_One
mathHelpers object should contain a method called double
ReferenceError: exerciseOne is not defined
testName1
Should add greeting method to userObject object.
ReferenceError: exerciseTwo is not defined
More info
ReferenceError: exerciseTwo is not defined
at eval (eval at n.evaluate (https://replbox.repl.it/public/replbox_javascript.42d3612391d31be3eb13.bundle.js:223:152082), <anonymous>:20:20)
at https://replbox.repl.it/public/replbox_javascript.42d3612391d31be3eb13.bundle.js:670:306174
at n.run (https://replbox.repl.it/public/replbox_javascript.42d3612391d31be3eb13.bundle.js:670:306398)
at n.execute (https://replbox.repl.it/public/replbox_javascript.42d3612391d31be3eb13.bundle.js:670:305169)
at e.R as queueRunnerFactory
at e.execute (https://replbox.repl.it/public/replbox_javascript.42d3612391d31be3eb13.bundle.js:670:263457)
at e.fn (https://replbox.repl.it/public/replbox_javascript.42d3612391d31be3eb13.bundle.js:670:316285)
at https://replbox.repl.it/public/replbox_javascript.42d3612391d31be3eb13.bundle.js:670:306108
at n.run (https://replbox.repl.it/public/replbox_javascript.42d3612391d31be3eb13.bundle.js:670:306398)
at t (https://replbox.repl.it/public/replbox_javascript.42d3612391d31be3eb13.bundle.js:670:305769)

I am just doing the way the video (https://www.youtube.com/watch?v=FNfaU-bVdqM) and lesson taught, but it doesn't work. What's the solution?

You are viewing a single comment. View All
Answered by GoodDeedNinja (7) [earned 5 cycles]
View Answer
wadecoplen (2)

@GoodDeedNinja There are many exercises that do not go along with the lesson. The syntax of a method according to the video is: greeting: function(){}, which is throwing the error stated above. Also, RETURN is never used in the videos, but is console.log is.. This is confusing, as console.log is not the same as RETURN.