As a beginner in programming, I am currently enrolled in an introductory JavaScript course. However, I am facing an issue with my assignment where the toString method is printing an array instead of a string. Despite thorough research, I have been unsuccessful in finding a solution to this problem. The objective of the assignment is as follows:
To create a constructor function named World (note that constructors should start with a capital letter).
The World object must include a property called plan which consists of an array of strings.
Create a prototype method for World that displays the content of the array with line breaks between each element (using \n as the line break character)
Instantiate a variable named world and execute its toString method.
Below is the code snippet that I have developed so far:
function World(plan){
this.plan = plan;
}
var plan = ["––––––––––",
"| _ |",
"| | |",
"|__| |",
"| ___| |",
"––––––––––"];
var funWorld = new World(plan);
World.prototype.plan = function() {
console.log(this.plan + "\n");
return this;
};
World.prototype.toString = function() {
return(this.plan);
};
console.log(funWorld.toString());
This is the current output that I am getting:
[
0: "––––––––––"
1: "| _ |"
2: "| | |"
3: "|__| |"
4: "| ___| |"
5: "––––––––––"
]
I am uncertain about where I might have made an error. Any guidance or assistance would be greatly appreciated.