Build a Bookmark Manager App - Build a Bookmark Manager App

Tell us what’s happening:

Tests 5, 19 and 20 arent passing even though it is working fine. I cant find an issue and have tried it without string concatination etc.

Test 23 isnt passing and the code isnt working like it should. I tried debugging by loging diffrent steps to the console but I cant find a solution. The code just doesnt do as told.

Thanks in advance for any help!

Your code so far

/* file: script.js */
const mainSection = document.getElementById("main-section");
const formSection = document.getElementById("form-section");
const addBookmarkBtn = document.getElementById("add-bookmark-button");
const categoryName = document.querySelector(".category-name");
const categoryDropdown = document.getElementById("category-dropdown");
const closeFormButton = document.getElementById("close-form-button");
const addBookmarkButtonForm = document.getElementById("add-bookmark-button-form");
const nameTag = document.getElementById("name")
const categoryTag = document.getElementById("category");
const urlTag = document.getElementById("url");
const bookmarkListSection = document.getElementById("bookmark-list-section");
const viewCategoryButton = document.getElementById("view-category-button");
const categoryList = document.getElementById("category-list");
const closeListBtn = document.getElementById("close-list-button");
const deleteBookmarkBtn = document.getElementById("delete-bookmark-button");


const bookmarksArr = [
  {
    name: "hey",
    category: "work",
    url: "dreamUrl"
  },
  {
    name: "bye",
    category: "news",
    url: "dreaUrl"
  },
  {
    name: "mind",
    category: "entertainment",
    url: "dreamUl"
  },
  {
    name: "hey",
    category: "miscellaneous",
    url: "dremUrl"
  }
]
localStorage.setItem("bookmarks", JSON.stringify(bookmarksArr))

const getBookmarks = () => {
  const bookmarksArr = JSON.parse(localStorage.getItem("bookmarks"));
  // console.log(bookmarksArr)
  if(!Array.isArray(bookmarksArr) || !bookmarksArr.every(b => typeof b === 'object' && b !== null)){
    return [];
  }else { 
    return bookmarksArr 
  }
}

const displayOrCloseForm = () => {
  mainSection.classList.toggle("hidden");
  formSection.classList.toggle("hidden");
}

addBookmarkBtn.addEventListener("click", ()=>{
   categoryName.innerText = categoryDropdown.value;
   displayOrCloseForm();
})

closeFormButton.addEventListener("click", ()=>{
  displayOrCloseForm()
})

addBookmarkButtonForm.addEventListener("click", ()=>{
  const bookmarks = getBookmarks();
  bookmarks.push({
    name: nameTag.value,
    category: categoryDropdown.value,
    url: urlTag.value
  })

   localStorage.setItem("bookmarks", JSON.stringify(bookmarks))

   nameTag.value = "";
   urlTag.value = "";

   displayOrCloseForm();
})

const displayOrHideCategory = () => { 
  mainSection.classList.toggle("hidden");
  bookmarkListSection.classList.toggle("hidden");
}

viewCategoryButton.addEventListener("click", ()=>{
  const bookmark = getBookmarks();
  categoryName.innerText = categoryDropdown.value;

  const filtered = bookmark.filter((e)=>e.category.toLowerCase() == categoryDropdown.value.toLowerCase())

  

  if(filtered.length == 0){
    categoryList.innerHTML = "<p>No Bookmarks Found</p>"
  }else if(filtered){
  

    filtered.forEach((e)=>{
      categoryList.innerHTML += `<input type="radio" id="${e.name}" value="${e.name}" name="radioBtn">
      <label for="${e.name}"><a href="${e.url}">${e.name}</a></label>`; 
    })
  }

  displayOrHideCategory()
})

closeListBtn.addEventListener("click", ()=>{
  displayOrHideCategory()
  categoryList.innerHTML = ""
});

deleteBookmarkBtn.addEventListener("click", ()=>{

  let buttons = document.querySelector('input[type="radio"]:checked');
  
  if(!buttons){
    alert("nothing selected");
    return
  }else{

  let bookmarks = JSON.parse(localStorage.getItem('bookmarks'));

  bookmarks = bookmarks.filter(bookmark => bookmark.name !== buttons.value)
  // console.log(bookmarks)

  localStorage.setItem('bookmarks', JSON.stringify(bookmarks)) 

  // console.log(JSON.parse(localStorage.getItem("bookmarks")))
  //update list
  const newBookmarks = JSON.parse(localStorage.getItem('bookmarks'));
 
  console.log(newBookmarks) 
 
  const filter = newBookmarks.filter((bookmark)=> bookmark.category === categoryDropdown.value)   

  console.log(filter) 
 
  if(filter.length == 0){
    categoryList.innerHTML = "<p>No Bookmarks Found</p>"
  }else{ 
  

    filter.forEach((e)=>{
      categoryList.innerHTML += `<input type="radio" id="${e.name}" value="${e.name}" name="radioBtn">
      <label for="${e.name}"><a href="${e.url}">${e.name}</a></label>`; 
    })}}
})

<!-- file: index.html -->

/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 OPR/133.0.0.0

Challenge Information:

Build a Bookmark Manager App - Build a Bookmark Manager App

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-bookmark-manager-app/66def5467aee701733aaf8cc.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @hayden.wasted,

For #5:

If a bookmark doesn’t contain a url key, will your code catch that?


Update: If you create a bookmark in two categories with the same name, then delete one, will just the bookmark in the current category be deleted?

Happy coding

Thank you for the response. idk if im just stupid or whats up but i made the changes as you said but it didnt change anything and I am once again facing a wall.

Here are the changes I made:

Issue #5=

if(!Array.isArray(bookmarksArr) || !bookmarksArr.every(b => typeof b === ‘object’ && b !== null) || !bookmarksArr.every(b => b.hasOwnProperty(“name”) && b.hasOwnProperty(“url”) && b.hasOwnProperty(“category”))){

return [];}

Issue 23:

const arr = [];

bookmarksArr.forEach((bookmark)=>{

if(bookmark.name == buttons.value && bookmarks.category == categoryDropdown.value){

  arr.push(bookmark)

}

})

bookmarks = bookmarks.filter(bookmark => !arr.includes(bookmark))

I suggest going through the user stories again to make sure you have implemented them exactly as asked. Then, if you still need more help, please post your updated code, formatted as follows:

There are two ways you can format your code to make it easier to read and test:

  1. After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)

  1. Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.

To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:

Thanks I found the mistake! have a good day