26. Change variable values


#1


https://www.codecademy.com/en/courses/getting-started-v2/4/3?curriculum_id=506324b3a7dffd00020bf661#


ReferenceError: Adam is not defined


// On line 2, declare a variable myName and give it your name.
var myName = Adam
// On line 4, use console.log to print out the myName variable.
console.log(myName);
// On line 7, change the value of myName to be just the first 2 
// letters of your name.
console.log(Adam.substring(0,2));
// On line 9, use console.log to print out the myName variable.
console.log(myName);


#2

Hi @abrashm use the variable myName :slight_smile:
Adam is not the variable, it is a string assigned to variable myName.

The indicated error usually gives hint to what error might be in the code. In this case, you have not define any variable name Adam, thus the console throws out ReferenceError: Adam is not defined because it could not find any Adam.


#3

done, now it says TYPE ERROR console log is not a function

// On line 2, declare a variable myName and give it your name.
var myName = "Adam"
// On line 4, use console.log to print out the myName variable.
console.log(myName);
// On line 7, change the value of myName to be just the first 2
// letters of your name.
console.log(myName.substring(0,2));
// On line 9, use console.log to print out the myName variable.
console.log(myName);


#4

your missing a semicolon after Adam line 2


#5

still the same error


#6

Try refresh your browser, I check the code, it works. After refresh see if it still throws out error. :slight_smile:

Edited: see my reply below about the lesson's instruction, your code is okay but it's not following the lesson.


#7

thanks should've just done that


#8

@abrashm, sorry just notice this, I have reread the instruction.

Your code works perfectly. But it is not what the lesson intended.

Look again.

Change the value of myName, the lesson did not ask you to use console.log.

So, use myName with the substring method, change the value of myName to first 2 letters of your name.

In the end, your console should print like this:

Adam
Ad

Only two words. :slight_smile:


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.