0

This is the JavaScript task that I want to perform

====================================================

  1. First, declare a variable named myArray and assign it to an empty array.

  2. Great! Now populate myArray with two strings. Put your full name in the first string, and your Skype handle in the second.

  3. Next, declare a function named cutName. It should expect a parameter name.

  4. cutName should return an array by breaking up the input string into individual words. For example "Douglas Crockford" should be returned as ["Douglas", "Crockford"]

  5. Declare a new variable named myInfo and assign it to an empty object literal.

  6. Add the following three key-value pairs to myInfo:

  • Key: fullName Value: The result of calling cutName on the name string within myArray.

  • Key: Skype: Value: The Skype handle within myArray.

  • Key: GitHub Value: If you have a GitHub handle, enter it here as a string. If not, set this to null instead.

This is my code that I wrote which I gets only the number 4 procedure wrong

var myArray = [];
myArray = ["Safianu Mohammed", "mohammedsafianu"];

function cutName(name) {
    var fname = name;
    return fname;
}

name = (cutName("Safianu Mohammed"));

var myInfo = {};

myInfo = {
    fullName: cutName(name),
    skype: myArray[1],
    github: "null"
};
1
  • How is FullName = CutName ? Both represent different information, are you looking for anything else ? Commented Apr 17, 2017 at 16:26

5 Answers 5

2
var myArray = [];
myArray = ["Safianu Mohammed", "mohammedsafianu"];

function cutName(name) {
    var fname = name; // Missing a bit...
    return fname;
}

name = (cutName("Safianu Mohammed"));

var myInfo = {};

myInfo = { // Reassigning = not your task
    fullName: cutName(name), // Why do you call cutName again??
    skype: myArray[1],
    github: "null" // Not null
};

How I would do it:

var myArray = [];
myArray.concat(["Safianu Mohammed", "mohammedsafianu"]);

function cutName(name) {
    return name.split(" ");
}


name = cutName(myArray[0]);

var myInfo = {};

Object.assign(myInfo, {
    fullName: name,
    skype: myArray[1],
    github: null
});
Sign up to request clarification or add additional context in comments.

Comments

2

I got mine to work like this...

var myArray = [];
var myArray = ["Jessica Smith", "BlackHorse"];
var cutName = function(name){
    return name.split(",")
}
cutName("Jessica Smith")

var myInfo = {};

Object.assign(myInfo, {
    fullName: cutName(myArray[0]),
    skype: myArray[1],
    github: null
});

Comments

0

I am not sure how the cutName function would work in your case as you try to split the string with ,, but in your name there is no comma in the full name.

One possible reason for your error is that you are using the split function on the array. The split function is available on the string, not on the array.

So, you need to use

var fname = myArray[0].split(", ");

instead of

var fname = myArray.split(", ");

split is a function on String and not on the array.

var myArray = [];
myArray = ["Safianu Mohammed", "mohammedsafianu"];

function cutName(name) {
    var fname = myArray[0].split(", ");
    return  fname;
}

name = (cutName("Safianu Mohammed"));

var myInfo = {};

myInfo = {
    fullName: cutName(name),
    skype: myArray[1],
    github: "null"
};

console.log(myInfo);

2 Comments

the name is passed, and why do you split by ", " ??
I am not clear how the FullName = CutName, this doesn't make sense. Need OP Inputs...
0

Here is what you're looking for:

var myArray = [];
myArray = ["Ethan Halfhide", "red"];

function cutName(name) {
    return name.split(" ");
}

var myInfo = {
    fullName: cutName(myArray[0]),
    favoriteColor: myArray[1],
    github: null
};

console.log(myInfo);

Comments

0
// Enter your code here
var myArray = []
myArray = (["west palmar","red"]);
function cutName (myArray){return myArray.split(" "); }

var myInfo = {};

name = cutName(myArray[0]);    

Object.assign(myInfo, {
    fullName: name,
    favoriteColor: myArray[1],
    github: null
});

1 Comment

This is my answer to the main question except i used favor color instead of skype. It work when call the Value: The result of calling cutName on the name string within myArray.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.