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 JavaScript Foundations Arrays Methods: Part 1

Toni Caktas
Toni Caktas
16,478 Points

help...totally stuck

Challenge 1 is a nightmare for a me and I am stuck Please help with correct answer

3 Answers

Tony Nguyen
Tony Nguyen
24,934 Points

For challenge #1, You have to move the <script> tag in between the </body> and </html> tags so that your javascript will work without putting additional code everytime.

  <body>
    <h1 id="title">JavaScript Foundations</h1>
    <h2>Variables: Basics</h2>

    <div id="container">
      This is a div with the id of "container"
    </div>
  </body>
  <script src="myscript.js"></script>
</html>
Toni Caktas
Toni Caktas
16,478 Points

On line 18, use a method on the 'spareWords' to set 'firstWord' to be first word of the 'spareWords' array whilst simultaneously removing it from the beginning of the array. Bummer! There was an error with your code: SyntaxError: Parse error PreviewRecheck work index.html

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <title> JavaScript Foundations: Arrays</title> 5 <style> 6 html { 7 background: #FAFAFA; 8 font-family: sans-serif; 9 } 10 </style> 11 </head> 12 <body> 13 <h1>JavaScript Foundations</h1> 14 <h2>Arrays: Methods Part 1</h2> 15 <script> 16 var spareWords = ["The","chimney","sweep's","dog"]; 17 var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"]; 18 var firstWord = spareWords.unshift(), 19 = spareWords.shift(); 20 var lastWord = spareWords; 21 saying; 22 saying; 23 </script> 24 </body> 25 </html>

David Smith
David Smith
21,220 Points

Hi there, post the code that you are having trouble with so we can offer you guidance on how to get to the correct answer.

To post code in the forums add three back ticks (```javascript), then the code on a new line, then on a new line finish with another three back ticks on a new line

Toni Caktas
Toni Caktas
16,478 Points

On line 18, use a method on the 'spareWords' to set 'firstWord' to be first word of the 'spareWords' array whilst simultaneously removing it from the beginning of the array. Bummer! There was an error with your code: SyntaxError: Parse error PreviewRecheck work index.html

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <title> JavaScript Foundations: Arrays</title> 5 <style> 6 html { 7 background: #FAFAFA; 8 font-family: sans-serif; 9 } 10 </style> 11 </head> 12 <body> 13 <h1>JavaScript Foundations</h1> 14 <h2>Arrays: Methods Part 1</h2> 15 <script> 16 var spareWords = ["The","chimney","sweep's","dog"]; 17 var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"]; 18 var firstWord = spareWords.unshift(), 19 = spareWords.shift(); 20 var lastWord = spareWords; 21 saying; 22 saying; 23 </script> 24 </body> 25 </html>

Toni Caktas
Toni Caktas
16,478 Points

On line 18, use a method on the 'spareWords' to set 'firstWord' to be first word of the 'spareWords' array whilst simultaneously removing it from the beginning of the array. Bummer! There was an error with your code: SyntaxError: Parse error PreviewRecheck work index.html

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <title> JavaScript Foundations: Arrays</title> 5 <style> 6 html { 7 background: #FAFAFA; 8 font-family: sans-serif; 9 } 10 </style> 11 </head> 12 <body> 13 <h1>JavaScript Foundations</h1> 14 <h2>Arrays: Methods Part 1</h2> 15 <script> 16 var spareWords = ["The","chimney","sweep's","dog"]; 17 var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"]; 18 var firstWord = spareWords.unshift(), 19 = spareWords.shift(); 20 var lastWord = spareWords; 21 saying; 22 saying; 23 </script> 24 </body> 25 </html>