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 Local Storage Project

Sean Flanagan
Sean Flanagan
33,235 Points

Localstorage won't save searches

Hi.

I typed in a search term and clicked the Search button but the term didn't appear.

This is my workspace:

https://w.trhou.se/5m891nekbk

I would appreciate any help.

3 Answers

Steven Parker
Steven Parker
231,127 Points

In index.html on line 45, the function "saveSearchString" takes no arguments. But the code body appears to be expecting an argument named "str".

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Steven.

I've made some changes to this function but still no luck.

function saveSearchString(str) {
      var searches = getRecentSearches();
      if(!str || searches.indexOf(str) > -1) {
        return false;
      }
      searches.push(str);
      localStorage.setItem("recentSearches", JSON.stringify(searches));
      return true;
    }

Is this right?

Cheers!

Steven Parker
Steven Parker
231,127 Points

Adding the "str" argument to the function was the only change I made and then each term I searched was added to the list.

Sean Flanagan
Sean Flanagan
33,235 Points

I've looked at my workspace, "Using Local Storage with JavaScript - Local Storage Project"

I can see my index.html but now the app.js file is missing and there are some files that don't belong there. In a folder called "stylesheets" are three files:

page.css.map, page.css and page.sass.

I don't know what's happened or what to do.

Sean

Steven Parker
Steven Parker
231,127 Points

The JavaScript is embedded in the HTML file. And I just assumed you wrote the CSS in sass and then compiled it. The HTML file uses the page.css.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Steven.

I previewed the workspace and it worked perfectly. Sorry about all that. It just came as a bit of a shock. I'd started a course about Sass and I thought the code from there had transferred to the Local Storage workspace. I panicked.

Thank you for all your help. I've given your first response both an up vote and Best Answer.

Sean