Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript DOM Scripting By Example Improving the Application Code Fix Function that Should be Creating Links

Shoaib Khan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Shoaib Khan
Front End Web Development Techdegree Graduate 21,177 Points

I need some help on getting this JS challenge started. Please help!

I need help understanding if I need to edit the function or do I just need to add to it where it says so? Where should I begin?

app.js
const languages = ['Python', 'JavaScript', 'PHP', 'Ruby', 'Java', 'C'];
const section = document.getElementsByTagName('section')[0];

// Accepts a language name and returns a wikipedia link
function linkify(language) {
  const a = document.createElement('a');
  const url = 'https://wikipedia.org/wiki/' + language + '_(programming_language)';
  a.href = url;
  return a;
}

// Creates and returns a div
function createDiv(language) {
  const div = document.createElement('div');
  const h2 = document.createElement('h2');
  const p = document.createElement('p');
  const link = linkify(language);

  h2.textContent = language;
  p.textContent = 'Information about ' + language;
  link.appendChild(p);

  div.appendChild(h2);

  // Your code below


  // end

  return div;
}

for (let i = 0; i < languages.length; i += 1) {
  let div = createDiv(languages[i]);

  section.appendChild(div);
}
index.html
<!DOCTYPE html>
<html>
<head>
  <title>Programming Languages</title>
  <style>
    body {
      font-family: sans-serif;
    }
  </style>
</head>
<body>
  <h1>Programming Languages</h1>
  <section></section>
  <script src="app.js"></script>
</body>
</html>

3 Answers

Shoaib Khan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Shoaib Khan
Front End Web Development Techdegree Graduate 21,177 Points

Hi Guys,

Brian Jensen helped me get this right. Here is the correct answer. The link was being stored in the "link" variable with a "p" element and I needed the function to "div.appendChild(link)" to the DOM.

 // Your code below
  div.appendChild(link);
  // end

Thanks again for all your help guys!

Shoaib Khan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Shoaib Khan
Front End Web Development Techdegree Graduate 21,177 Points

I was able to get the links to show up by adding to the for loop, but it still wont accept it as a valid answer. Your thoughts?

for (let i = 0; i < languages.length; i += 1) {
  let div = createDiv(languages[i]);
  let divLinks = createDiv(linkify(languages[i]));

  section.appendChild(div);
  section.appendChild(divLinks);
}

You should modify the createDiv() function instead of the loop. Notice the comment:

  // Your code below


  // end

In the function there is a link variable and the error message provides a hint "Hint: only one line of code needs to be added to complete this challenge"