26. Change variable values


#1


26. Change variable values


Oops, try again. There was a problem with your syntax.


Replace this line with your code. 
// On line 2, declare a variable myName and give it your name.
var myName="Jacob";
// 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.
var  = myName.substring(0,2);
// On line 9, use console.log to print out the myName variable.
console.log(myName);


#2

To change the value simply redefine by assigning the new value. Don't re-declare it, though. A variable only needs to be declared with var one time.

myName = myName.substring(0,2);

Declare a variable

var myVar;

Define a variable

myVar = "some value";

Declare AND define

var myName = "Jacob";

Redefining we've touched upon above.


#3

thanks, sorry for late reply back


#4

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