Skip to content

Commit f6476cd

Browse files
committed
data abstraction hw
1 parent 77c46af commit f6476cd

1 file changed

Lines changed: 47 additions & 13 deletions

File tree

_notebooks/Homework/2025-10-06-data-abstraction_penguins_hw.ipynb

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,53 @@
7070
},
7171
"outputs": [],
7272
"source": [
73+
"%%javascript\n",
74+
"\n",
7375
"// put popcorn hack 1 code here:\n",
7476
"\n",
75-
"let username = \"Giuseppe\";\n",
76-
"let password = \"giuseppe_very_awesome_password\";\n",
77+
"let username = \"Hi\";\n",
78+
"let password = \"hi_very_awesome_password\";\n",
7779
"\n",
7880
"// part 1\n",
7981
"function Account()\n",
8082
"{\n",
81-
"\n",
83+
"\tconsole.log(username, password);\n",
8284
"}\n",
8385
"\n",
8486
"// part 2\n",
85-
"function ChangeUsername()\n",
87+
"function ChangeUsername(newUserName)\n",
8688
"{\n",
87-
"\n",
89+
"\tusername = newUserName;\n",
8890
"}\n",
8991
"\n",
9092
"// part 3\n",
91-
"function ChangePassword()\n",
93+
"function ChangePassword(newPassword)\n",
9294
"{\n",
93-
"\n",
95+
"\tpassword = newPassword;\n",
9496
"}\n",
9597
"\n",
9698
"// part 4\n",
9799
"function Login(_username, _password)\n",
98100
"{\n",
99-
"\tif (/* check if equal */ && /* check if equal */)\n",
100-
"\t{\n",
101+
"\tif (_username === username && _password === password) {\n",
101102
"\t\t// print out logged in succesfully\n",
103+
"\t\tconsole.log(\"Login Sucsess!\");\n",
102104
"\t\treturn true;\n",
103105
"\t}\n",
104106
"\telse\n",
105107
"\t{\n",
106108
"\t\t// print out log in failure\n",
109+
"\t\tconsole.log(\"Login Failure\");\n",
107110
"\t\treturn false;\n",
108111
"\t}\n",
109112
"}\n",
110-
"\n"
113+
"\n",
114+
"// Test\n",
115+
"ChangeUsername(\"Krish\");\n",
116+
"ChangePassword(\"password\");\n",
117+
"Account();\n",
118+
"Login(\"Krish\", \"password\");\n",
119+
"Login(\"Krish\", \"P@ssword\");"
111120
]
112121
},
113122
{
@@ -142,7 +151,16 @@
142151
"outputs": [],
143152
"source": [
144153
"// popcorn hack 2 code goes here:\n",
145-
"\n"
154+
"\n",
155+
"class House {\n",
156+
" constructor(cost, age, size) {\n",
157+
" this.cost = cost;\n",
158+
" this.age = age;\n",
159+
" this.size = size;\n",
160+
" }\n",
161+
"}\n",
162+
"\n",
163+
"anishsHouse = new House(700000, 1, 7000);\n"
146164
]
147165
},
148166
{
@@ -177,26 +195,42 @@
177195
},
178196
"outputs": [],
179197
"source": [
198+
"%%javascript\n",
180199
"// final task code goes here:\n",
181200
"\n",
182201
"class Player\n",
183202
"{\n",
184203
"\t// part 1\n",
185204
"\tconstructor()\n",
186205
"\t{\n",
187-
"\n",
206+
"\t\tthis.positionX = 0;\n",
207+
"\t\tthis.velocityX = 0;\n",
188208
"\t}\n",
189209
"\n",
190210
"\t// part 2\n",
211+
"\tmoveLeft() {\n",
212+
"\t\tthis.velocityX = -100;\n",
213+
"\t}\n",
214+
"\tmoveRight() {\n",
215+
"\t\tthis.velocityX = 100;\n",
216+
"\t}\n",
191217
"\n",
192218
"\n",
193219
"\t// part 3\n",
220+
"\tupdatePosition() {\n",
221+
"\t\tthis.positionX += this.velocityX;\n",
222+
"\t\tconsole.log(\"We have updated the position to:\", this.positionX);\n",
223+
"\t}\n",
194224
"}\n",
195225
"\n",
196226
"// part 4\n",
197227
"let player = new Player;\n",
198228
"\n",
199-
"// call the functions on player here:\n"
229+
"// call the functions on player here:\n",
230+
"player.moveLeft();\n",
231+
"player.updatePosition();\n",
232+
"player.moveRight();\n",
233+
"player.updatePosition();"
200234
]
201235
},
202236
{

0 commit comments

Comments
 (0)