|
70 | 70 | }, |
71 | 71 | "outputs": [], |
72 | 72 | "source": [ |
| 73 | + "%%javascript\n", |
| 74 | + "\n", |
73 | 75 | "// put popcorn hack 1 code here:\n", |
74 | 76 | "\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", |
77 | 79 | "\n", |
78 | 80 | "// part 1\n", |
79 | 81 | "function Account()\n", |
80 | 82 | "{\n", |
81 | | - "\n", |
| 83 | + "\tconsole.log(username, password);\n", |
82 | 84 | "}\n", |
83 | 85 | "\n", |
84 | 86 | "// part 2\n", |
85 | | - "function ChangeUsername()\n", |
| 87 | + "function ChangeUsername(newUserName)\n", |
86 | 88 | "{\n", |
87 | | - "\n", |
| 89 | + "\tusername = newUserName;\n", |
88 | 90 | "}\n", |
89 | 91 | "\n", |
90 | 92 | "// part 3\n", |
91 | | - "function ChangePassword()\n", |
| 93 | + "function ChangePassword(newPassword)\n", |
92 | 94 | "{\n", |
93 | | - "\n", |
| 95 | + "\tpassword = newPassword;\n", |
94 | 96 | "}\n", |
95 | 97 | "\n", |
96 | 98 | "// part 4\n", |
97 | 99 | "function Login(_username, _password)\n", |
98 | 100 | "{\n", |
99 | | - "\tif (/* check if equal */ && /* check if equal */)\n", |
100 | | - "\t{\n", |
| 101 | + "\tif (_username === username && _password === password) {\n", |
101 | 102 | "\t\t// print out logged in succesfully\n", |
| 103 | + "\t\tconsole.log(\"Login Sucsess!\");\n", |
102 | 104 | "\t\treturn true;\n", |
103 | 105 | "\t}\n", |
104 | 106 | "\telse\n", |
105 | 107 | "\t{\n", |
106 | 108 | "\t\t// print out log in failure\n", |
| 109 | + "\t\tconsole.log(\"Login Failure\");\n", |
107 | 110 | "\t\treturn false;\n", |
108 | 111 | "\t}\n", |
109 | 112 | "}\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\");" |
111 | 120 | ] |
112 | 121 | }, |
113 | 122 | { |
|
142 | 151 | "outputs": [], |
143 | 152 | "source": [ |
144 | 153 | "// 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" |
146 | 164 | ] |
147 | 165 | }, |
148 | 166 | { |
|
177 | 195 | }, |
178 | 196 | "outputs": [], |
179 | 197 | "source": [ |
| 198 | + "%%javascript\n", |
180 | 199 | "// final task code goes here:\n", |
181 | 200 | "\n", |
182 | 201 | "class Player\n", |
183 | 202 | "{\n", |
184 | 203 | "\t// part 1\n", |
185 | 204 | "\tconstructor()\n", |
186 | 205 | "\t{\n", |
187 | | - "\n", |
| 206 | + "\t\tthis.positionX = 0;\n", |
| 207 | + "\t\tthis.velocityX = 0;\n", |
188 | 208 | "\t}\n", |
189 | 209 | "\n", |
190 | 210 | "\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", |
191 | 217 | "\n", |
192 | 218 | "\n", |
193 | 219 | "\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", |
194 | 224 | "}\n", |
195 | 225 | "\n", |
196 | 226 | "// part 4\n", |
197 | 227 | "let player = new Player;\n", |
198 | 228 | "\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();" |
200 | 234 | ] |
201 | 235 | }, |
202 | 236 | { |
|
0 commit comments