JS Assignment 13 Intro to Classes in Javascript
nda1 (2)

Hey could anyone who has done the lambda precourse work help me, I do not understand why my answer is wrong. here is the assignment link: https://repl.it/student/submissions/6438375

function ClassOne(name, pw, mail){
// Exercise One: In this exercise you will be creating your own class!
// You are currently in the class, you are given three strings, name, pw, and mail.
// You need to create three properties on this class.
// Those properties are: 'username', 'password', and 'email'
// Set the value of username to name,
// Set the value of password to pw,
// Set the value of email to mail

this was my answer>>>
function ClassOne(username, password, email) {
this.username = name;
this.password = pw;
this.email = mail;
}

You are viewing a single comment. View All
ArchieMaclean (584)

When you declare a variable, the left side has to be not known, and the right side has to be known.
When you are doing

this.username = name;

the computer does not know the right hand side of the equation - you never said what name was.
I'm not giving you the whole answer, but hopefully you should be able to work it out from that :)

Please upvote if this helps :)

nda1 (2)

@ArchieMaclean I’m sorry, I’m still confused.

ArchieMaclean (584)

@nda1 This is your answer:

function ClassOne(username, password, email) {
  this.username = name;
  this.password = pw;
  this.email = mail;
}

But you never say what name, pw or mail are, so the computer gives an error when you say

this.username = name

Because it doesn't know what name is. This happens when declaring all 3 variables.

nda1 (2)

@ArchieMaclean do you mean like this?

const ann = new ClassOne ('Ann', '1qwert', '[email protected]');

ArchieMaclean (584)

@nda1 No. If you look at the code you made:

function ClassOne(username, password, email) {
  this.username = name;
  this.password = pw;
  this.email = mail;
}

you are never saying what name is equal to. At the top, you have

function ClassOne(username, password, email) {

, but you never declare name, pw or mail.

nda1 (2)

@ArchieMaclean but it is just asking to assign those values, not declare it.
}

nda1 (2)

@ArchieMaclean the assignment did not ask me to the declare it so I assumed i did not have too.

ArchieMaclean (584)

@nda1 No not like that. I'm just going to give you the solution.
Your code is like this:

function ClassOne(username, password, email) {
  this.username = name;
  this.password = pw;
  this.email = mail;
}

However, I have explained above that this doesn't work. To fix it, you need to do this:

function ClassOne(name,pw,mail) {     // this has been changed
  this.username = name;
  this.password = pw;
  this.email = mail;
}

Now you've done that, the computer knows what name, pw and mail are, so it runs.

nda1 (2)

@ArchieMaclean I tried that before and it did not work.

ArchieMaclean (584)

@nda1 Hmm.. it should do. Do you have a link to the repl?

ArchieMaclean (584)

@nda1 I don't have permission to that. Could you copy-paste it into a repl?

nda1 (2)

@ArchieMaclean i tried posting it in the javascript one but it keeps defaulting to node.js but here it is https://repl.it/@nda1/practice-problem

ArchieMaclean (584)

@nda1 Sorry for giving you the wrong repl type ;(
Here is a fixed version of the repl.

nda1 (2)

@ArchieMaclean sorry but I am still getting an error. the message stating "Expected undefined to be 'Dan'."

ArchieMaclean (584)

@nda1 Do you get this when you run my repl? If not, what did you change?

nda1 (2)

@ArchieMaclean yes, I got that message when i ran your code but also when I ran mine.

ArchieMaclean (584)

@nda1 I don't get any error when running my code...