Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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>