Pass an Array as Props

Tell us what’s happening:

It keeps failing test - List should put array values within p tag. The p tag is present. I don’t understand why this test is failing. Please help.

Your code so far


const List= (props) => {
  { /* change code below this line */ }
  return (<p>{props.tasks.join(',')}</p>);
  { /* change code above this line */ }
};

class ToDo extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div>
        <h1>To Do Lists</h1>
        <h2>Today</h2>
        { /* change code below this line */ }
        <List tasks={["walk dog", "workout"]}/>
        <h2>Tomorrow</h2>
        <List tasks={["walk dog", "workout","sleep"]}/>
        { /* change code above this line */ }
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/pass-an-array-as-props

Hi @saumgarg0402,

Your answer is right, but your problem that you don’t make a space after tasks array like this
<List tasks = {["walk dog","workout"]} />

If you stuck just copy and paste the solution:

const List= (props) => {
  { /* change code below this line */ }
  return <p>{props.tasks.join(', ')}</p>
  { /* change code above this line */ }
};

class ToDo extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div>
        <h1>To Do Lists</h1>
        <h2>Today</h2>
        { /* change code below this line */ }
        <List tasks= { ["walk","dog","workout"] } />
        <h2>Tomorrow</h2>
        <List tasks = { ["shopping","Playing football","programming"] } />
        { /* change code above this line */ }
      </div>
    );
  }
};

Hope this help you to solve example, good luck and have a nice day.

Regards,
Ali Mosaad

It does NOT work. I am still getting
// running test
The List component should render the value from the tasks prop in the p tag.
// tests completed

The answer lies here my friend. Sometimes it’s the tiniest change.

/* Instructions */
Use join(', ')

/* you */
join(',')
4 Likes

Hi @bobxchen,

I agree with @JM-Mendez for his point, try to do what @JM-Mendez say.

Good luck @bobxchen

Regards,
Ali Mosaad

That was my issue…thanks for that catch!