Budget App : Syntax and localStorage Logic doubt

I am working on a Budget App and trying to make the edit and delete buttons work. I am using an onClick to trigger the functions and passing the parameters of the object aka “id”, and “object” as seen in the first screenshot. Am I making a mistake in the syntax or logic? Because, upon console logging, the “id” is passed successfully but not the “object” (As seen in the second screenshot).

Also what logic can be used in order to delete the particular entry from localStorage? It’s been a while since I have worked on JS, so need the help.

Syntax of the object getting saved in localStorage :
{id: 1, object: “pen”, price: “20”}


CodePen Link

i can’t see where you are writing to localstorage.
are you checking your localstorage files in devtools?

edit#: found it. i’ll have a look but i’m just noobing around myself

i suspect you’ve written over the code since you aksed this question so i cant see where the problem is or where rewriteItem is called

1 Like

both the rewriteItem( ) and deleteItem() are being called using onClick as shown in the first screenshot. In rewriteItem (), I have tried to pass the required arguments while in the deleteItem() , I was trying to pass the event to execute the function (just to try which method was working better). Unfortunately, in both methods I ended up encountering issues:

  1. Object being undefined when I try to use the argument passing option.
  2. Not able to figure out how to delete the item from local Storage when using the event passing option.

<button><i class="fa-solid fa-pen-to-square edit" onClick="rewriteItem(${id,object})"></i></button>
Here: ${id,object}
You need to add a , manually between id and object, or else it will only insert one of them (I think the last one)
document.write(${123, “abc”}) results in abc
document.write(${123 +", "+“abc”}) results in 123,abc

But you said it’s only getting the id, so there is an error already earlier

1 Like

Will try this out. Thanks for the help! :+1:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.