File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525
2626 delete product.newProperty;
2727 console.log(product);
28- */
28+ */
2929 const product2 = {
30- name : 'shirt'
30+ name : 'shirt' ,
31+ 'delivery-time' :'a day' ,
32+ rating :{
33+ starts :4.5 ,
34+ count :87
35+ } ,
36+ fun : function function1 ( ) {
37+ console . log ( 'function inside object' )
38+ }
3139 } ;
40+
41+
42+
43+
44+
3245 console . log ( product2 )
3346 console . log ( product2 [ 'name' ] )
47+ console . log ( product2 [ 'delivery-time' ] ) ;
48+
49+ console . log ( product2 . rating . count )
50+ console . log ( product2 . rating [ 'count' ] )
51+
52+ product2 . fun ( )
53+ console . log ( typeof console . log ) ;
54+
55+
56+ console . log ( JSON . stringify ( product2 ) ) ;
57+
58+ const jasonString = JSON . stringify ( product2 ) ;
59+
60+ console . log ( JSON . parse ( jasonString ) ) ;
61+
62+
3463
35- </ script >
36- </ body >
64+ </ script >
65+ </ body >
3766</ html >
Original file line number Diff line number Diff line change 2929
3030 < button onclick ="
3131 object.WINS = 0;
32- object.LOSES = 0;
32+ object.LOSSES = 0;
3333 object.TIES = 0;
34+ localStorage.removeItem('Score');
3435
3536 "> RESET BUTTON</ button >
3637
3738
3839
3940 < script >
4041
41- const object = {
42+ let object = JSON . parse ( localStorage . getItem ( 'Score' ) ) || {
4243 WINS :0 ,
43- LOSES :0 ,
44+ LOSSES :0 ,
4445 TIES :0
4546 } ;
47+
48+ /*if (!object){
49+ object ={
50+ WINS:0,
51+ LOSSES:0,
52+ TIES:0
53+ };
54+ } */
55+
56+
4657
4758
4859 function human ( playerMove ) {
5263 // scissor
5364 if ( playerMove === 'SCISSORS' ) {
5465 if ( computerMove === 'Rock' ) {
55- result = 'YOU LOSES .' ;
66+ result = 'YOU LOSE .' ;
5667 } else if ( computerMove === 'Paper' ) {
5768 result = 'YOU WINS.' ;
5869 } else if ( computerMove === 'Scissors' ) {
6778 } else if ( computerMove === 'Paper' ) {
6879 result = 'TIES.' ;
6980 } else if ( computerMove === 'Scissors' ) {
70- result = 'YOU LOSES .' ;
81+ result = 'YOU LOSE .' ;
7182 }
7283
7384
7889 if ( computerMove === 'Rock' ) {
7990 result = 'TIES.' ;
8091 } else if ( computerMove === 'Paper' ) {
81- result = 'YOU LOSES .' ;
92+ result = 'YOU LOSE .' ;
8293 } else if ( computerMove === 'Scissors' ) {
8394 result = 'YOU WINS.' ;
8495 }
8899
89100 if ( result === 'YOU WINS.' ) {
90101 object . WINS += 1 ;
91- } else if ( result === 'YOU LOSES .' ) {
92- object . LOSES += 1 ;
102+ } else if ( result === 'YOU LOSE .' ) {
103+ object . LOSSES += 1 ;
93104 } else if ( result === 'TIES.' ) {
94105
95106 object . TIES += 1 ;
96107 }
97108
109+ // localStorage
110+ localStorage . setItem ( 'Score' , JSON . stringify ( object ) ) ;
111+
112+
98113
99114 alert ( `You picked ${ playerMove } .Computer picked ${ computerMove } .You ${ result }
100- score WINS:-${ object . WINS } LOSES :-${ object . LOSES } TIES:-${ object . TIES } ` ) ;
115+ score WINS:-${ object . WINS } LOSSES :-${ object . LOSSES } TIES:-${ object . TIES } ` ) ;
101116 }
102117
103118
You can’t perform that action at this time.
0 commit comments