@@ -34,7 +34,33 @@ console.log("\nTask Completed!");
34
34
console . log ( "-------------------------------------------------" ) ;
35
35
console . log ( "Activity 3: " ) ;
36
36
37
+ const sessionStorage = new LocalStorage ( './session' ) ;
37
38
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 ) ;
38
64
39
65
console . log ( "-------------------------------------------------" ) ;
40
66
console . log ( "Activity 4: " ) ;
0 commit comments