Question 26. help? = intro to javaScript


#1

Instructions
Follow the instructions on line 1, line 3, line 5 and line 8. We're using this method to show you the order in which you tell the computer what to do is very important.

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


#3

On this line,

you were only asked to print out your name which I assume you know how to do,

example = "string"
console.log(example) // This code will print out string

Here,

You cannot achieve the desired result with the method you are trying to use but if you use the substring method it will be much more simpler,

for example,

example = "Dave"
console.log(example.substring(0, 2)); // This will only print out Da

Lastly here,

you have only been asked to print out my name again which I have showed you how to do above,

example = "string"
console.log(example) // This code will print out string

#4

sorry but your instructions are extremely confusing. I tried out your 'examples' and they did not work, even though I used "Dave" for every answer. Please explain. Thanks.


#5

Let me see your updated code :slight_smile:


#6

:blush:

// On line 2, declare a variable myName and give it your name.

console.log("Dave") ;
// On line 4, use console.log to print out the myName variable.

example = "Dave" ;
console.log(example);

// On line 7, change the value of myName to be just the first 2

example = "Dave" ;
console.log(example.substring(0, 2) );

// On line 9, use console.log to print out the myName variable.

example = "Dave";
console.log(example);


#7

Your code is unable to pass the SCT because they asked you to declare a variable named myName not example so just change all the example's to myName's,

// On line 2, declare a variable myName and give it your name.

var myName = "Dave"; // You can put your own name lol

// 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 = "Dave"

// On line 9, use console.log to print out the myName variable.

console.log(myName.substring(0, 2));

#8

my code works now. thanks. i was also aware i could put my own name but i used 'dave' to make it more simple, your explanation was very confusing. thanks though!

Passed:

// On line 2, declare a variable myName and give it your name.
var myName = "Angelo"
// 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.
var myName = "Angelo"


#9

You're welcome :slight_smile:


#10

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