Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 014a2a4

Browse files
Chore: Activity-3 completed for Day-20
1 parent 910fd31 commit 014a2a4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎Day20/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,33 @@ console.log("\nTask Completed!");
3434
console.log("-------------------------------------------------");
3535
console.log("Activity 3: ");
3636

37+
const sessionStorage = new LocalStorage('./session');
3738

39+
// Task 5: Write a script to save a string value to sessionStorage and retrieve it. Log the retrieved value.
40+
const stringValue = "Hello, Node.js!";
41+
sessionStorage.setItem('greeting', stringValue);
42+
43+
// Retrieve and log the string value from sessionStorage
44+
const retrievedString2 = sessionStorage.getItem('greeting');
45+
console.log('Retrieved string from sessionStorage:', retrievedString2);
46+
47+
// Task 6: Write a script to save an object to sessionStorage by converting it to a JSON string. Retrieve and parse the object, then log it.
48+
49+
// Task 6: Save an object to sessionStorage by converting it to a JSON string
50+
const userObject = {
51+
name: "Yash K. Saini",
52+
email: "yashkumarsaini101@gmail.com",
53+
age: 20
54+
};
55+
56+
// Convert object to JSON string and save to sessionStorage
57+
sessionStorage.setItem('user', JSON.stringify(userObject));
58+
59+
// Retrieve and parse the object from sessionStorage
60+
const retrievedObjectJSON = sessionStorage.getItem('user');
61+
const retrievedObject2 = JSON.parse(retrievedObjectJSON);
62+
63+
console.log('Retrieved object from sessionStorage:', retrievedObject2);
3864

3965
console.log("-------------------------------------------------");
4066
console.log("Activity 4: ");

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /