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 trialKevin Moreno
Full Stack JavaScript Techdegree Student 4,047 PointsDOM Scripting by example.
Can someone point be in the right direction for this challenge. It says one line of code is necessary; however, i don't understand why the missing line is preventing the divs to display on screen
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);
}
<!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>
1 Answer
Simon Coates
8,377 PointsThe question includes the text "This code should create a sequence of div elements that each hold a headline above and a link below.". Look for the code related to getting heading onto the page. Look for the code related to link and think "what is missing?". (you asked me to point you in the right direction rather than just post the answer. If you want more, just specify. If you just want the answer, then try https://teamtreehouse.com/community/this-code-should-create-a-sequence-of-div-elements-that-each-hold-a-headline-above-and-a-link-below-currently-only-the-4 )
Kevin Moreno
Full Stack JavaScript Techdegree Student 4,047 PointsKevin Moreno
Full Stack JavaScript Techdegree Student 4,047 PointsThanks for that figured it out! Glaring right in front of me.