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 trialJonah Shi
10,140 PointsWhy I can not write these javascript code into HTML, this is for "javascript array iteration method" course
Hi: Not want to skip node.js installation. I write the code in HTML, but when I open the console in Chrome, its all blank, but if I type straight into console. it works.
Below is the code <html> <head> <meta charset="UTF-8"> <title>Javscript iteration</title> <script type="Javscript">
var prices = [6.75, 3.10, 4.00, 8.12],
sum = 0;
prices.forEach(function(price) {
sum += price;
});
console.log(sum);
</script>
</head> <body>
</body> </html>
1 Answer
Steven Parker
231,269 PointsYou might try placing the script in the body instead of the head, the browser behavior regarding console log might be different for the sections.
Another thing you could try is rendering the result to the page instead of logging to the console (document.write(sum);
).