https://beta.freecodecamp.org/en/challenges/es6/use-class-syntax-to-define-a-constructor-function
The default code to be changed incorrectly says "change between these lines," when more extensive editing needs to be done. Current state:
function makeClass() {
"use strict";
/* Alter code below this line */
/* Alter code above this line */
return Vegetable;
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'
My solution to this challenge (bottom of page) shows the issue.
Suggested replacement:
/* Alter code below this line */
function makeClass() {
"use strict";
return Vegetable;
}
/* Alter code above this line */
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'
class Vegetable {
constructor(name){
this.name = name;
}
}
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot
the reference above is wrong. I copied the wrong issue number. sorry.
thanks for reporting the issue @vipatron
@raisedadead In my openion, not only the comments should be moved but also the code should be simplified.
This is the location of the lines to be changed in the seed.
The following is the current challengeSeed:
"challengeSeed": [
"function makeClass() {",
" \"use strict\";",
" /* Alter code below this line */",
"",
" /* Alter code above this line */",
" return Vegetable;",
"}",
"const Vegetable = makeClass();",
"const carrot = new Vegetable('carrot');",
"console.log(carrot.name); // => should be 'carrot'"
],
The following is what the challengeSeed should be changed to:
"challengeSeed": [
" /* Alter code below this line */",
"function Vegetable() {",
" \"use strict\";",
"",
"}",
" /* Alter code above this line */",
"const carrot = new Vegetable('carrot');",
"console.log(carrot.name); // => should be 'carrot'"
],
@vipatron @ahmadabdolsaheb Hello, I wanted to contriubute to this PR so I started to take a look at instructions and what the challenge was asking for. I do believe the original challengeSeed is posed correctly. Without giving away to much, read my additional notes below to help you solve this challenge:
function makeClass() {
"use strict";
/* Alter code below this line */
/ * Use the "class" keyword to create a Vegetable class here */
class class_name_here{
/ * Now create a constructor here to set "this.name" equal to the argument being past */
}
/* Alter code above this line */
return Vegetable;
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'
I have taken a stab at correcting the helper comments for this lesson.
Hi @rohanBagchi
I would suggest you also look at the code simplification that @ahmadabdolsaheb suggested that needs to be done to the challenge. What he is suggesting would make the initial code easier to read.
The current seed is absolutely fine, because it asks the user to create a class inside the makeClass() function & return it & passes the challenge with the following code:
function makeClass() {
"use strict";
/* Alter code below this line */
class Vegetable{
constructor(name){
this.name=name;
}
}
/* Alter code above this line */
return Vegetable;
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'
This way of returning a class from a function refers to the fact that a class is nothing but a kind of JS function internally which can be returned from another function & assigned to other variables just like any other JS function or object.
So, I think this is not an issue & should be closed.
Although @dearhakeemdavis 's solution seems logical as it will clear all the confusions regarding this challenge. So, either one can add few more comments as suggested by @dearhakeemdavis or leave it as it be. Current "Change between these lines" are perfect otherwise,
I'm closing this issue as stale since it hasn't been active lately. If you think this is still relevant to the newly updated platform, please explain why, then reopen it.
Most helpful comment
The current seed is absolutely fine, because it asks the user to create a class inside the makeClass() function & return it & passes the challenge with the following code:
This way of returning a class from a function refers to the fact that a class is nothing but a kind of JS function internally which can be returned from another function & assigned to other variables just like any other JS function or object.
So, I think this is not an issue & should be closed.
Although @dearhakeemdavis 's solution seems logical as it will clear all the confusions regarding this challenge. So, either one can add few more comments as suggested by @dearhakeemdavis or leave it as it be. Current "Change between these lines" are perfect otherwise,