fix(curriculum): allow optional spacing for assignment operator (#53723)

This commit is contained in:
Jessica Wilkins
2024-02-16 13:03:50 -08:00
committed by GitHub
parent 3ef8a4bf02
commit ced4ba4a0c
19 changed files with 33 additions and 33 deletions

View File

@@ -16,7 +16,7 @@ You should move the code nested inside the first `if` statement (except the firs
```js
({ test: () => {
assert.match(code, /def\s+make_allowed_move\(\s*rod1\s*,\s*rod2\s*\):\s+forward\s+=\s+False\s+if\s+not\s+rods\s*\[\s*target\s*\]\s*:\s+forward\s*=\s*True\s+elif\s+rods\s*\[\s*source\s*\]\s+and\s+rods\s*\[\s*source\s*\]\s*\[\s*-1\s*\]\s*<\s*rods\s*\[\s*target\s*\]\s*\[\s*-\s*1\s*\]\s*:\s+forward\s*=\s*True\s+if\s+forward\s*:\s+print\(\s*f'Moving\sdisk\s\{\s*rods\s*\[\s*source\s*\]\s*\[\s*-\s*1\s*\]\s*\}\sfrom\s\{\s*source\s*\}\sto\s\{\s*target\s*\}'\s*\)\s+rods\s*\[\s*target\s*\]\s*\.append\(\s*rods\s*\[\s*source\s*\]\s*\.pop\(\s*\)\s*\)\s+else\s*:\s+print\(\s*f'Moving\sdisk\s\{\s*rods\s*\[\s*target\s*\]\s*\[\s*-\s*1\s*\]\s*\}\sfrom\s\{\s*target\s*\}\sto\s\{\s*source\s*\}'\s*\)\s+rods\s*\[\s*source\s*\]\s*\.append\(\s*rods\s*\[\s*target\s*\]\s*\.pop\(\s*\)\s*\)\s+#\s*display\sour\sprogress\s+print\(\s*rods\s*\)/);
assert.match(code, /def\s+make_allowed_move\(\s*rod1\s*,\s*rod2\s*\):\s+forward\s*=\s*False\s+if\s+not\s+rods\s*\[\s*target\s*\]\s*:\s+forward\s*=\s*True\s+elif\s+rods\s*\[\s*source\s*\]\s+and\s+rods\s*\[\s*source\s*\]\s*\[\s*-1\s*\]\s*<\s*rods\s*\[\s*target\s*\]\s*\[\s*-\s*1\s*\]\s*:\s+forward\s*=\s*True\s+if\s+forward\s*:\s+print\(\s*f'Moving\sdisk\s\{\s*rods\s*\[\s*source\s*\]\s*\[\s*-\s*1\s*\]\s*\}\sfrom\s\{\s*source\s*\}\sto\s\{\s*target\s*\}'\s*\)\s+rods\s*\[\s*target\s*\]\s*\.append\(\s*rods\s*\[\s*source\s*\]\s*\.pop\(\s*\)\s*\)\s+else\s*:\s+print\(\s*f'Moving\sdisk\s\{\s*rods\s*\[\s*target\s*\]\s*\[\s*-\s*1\s*\]\s*\}\sfrom\s\{\s*target\s*\}\sto\s\{\s*source\s*\}'\s*\)\s+rods\s*\[\s*source\s*\]\s*\.append\(\s*rods\s*\[\s*target\s*\]\s*\.pop\(\s*\)\s*\)\s+#\s*display\sour\sprogress\s+print\(\s*rods\s*\)/);
}
})
```

View File

@@ -14,13 +14,13 @@ Turn the expression inside your `for` loop into an `if` statement. Use the expre
You should turn `constraint <= len(re.findall(pattern, password))` into the `if` condition.
```js
({ test: () => assert.match(code, /^(\s*)for.+:\s*^\1(\s{4})if\s+constraint\s* <=\s*len\s*\(\s*re\.findall\s*\(\s*pattern\s*,\s*password\s*\)\s*\)\s*:/m) })
({ test: () => assert.match(code, /^(\s*)for.+:\s*^\1(\s{4})if\s+constraint\s*<=\s*len\s*\(\s*re\.findall\s*\(\s*pattern\s*,\s*password\s*\)\s*\)\s*:/m) })
```
You should increment `count` by one inside your new `if` statement.
```js
({ test: () => assert.match(code, /^(\s*)for.+:\s*^\1(\s{4})if\s+constraint\s* <=\s*len\s*\(\s*re\.findall\s*\(\s*pattern\s*,\s*password\s*\)\s*\)\s*:\s*^\1\2\2(count\s*\+=\s*1|count\s*=\s*count\s*\+\s*1)/m) })
({ test: () => assert.match(code, /^(\s*)for.+:\s*^\1(\s{4})if\s+constraint\s*<=\s*len\s*\(\s*re\.findall\s*\(\s*pattern\s*,\s*password\s*\)\s*\)\s*:\s*^\1\2\2(count\s*\+=\s*1|count\s*=\s*count\s*\+\s*1)/m) })
```
# --seed--

View File

@@ -16,13 +16,13 @@ Also, set the `audio.title` property equal to `song.title`. This tells the audio
You should not modify the existing `playSong` function and its content.
```js
assert.match(code, /const\s+playSong\s*=\s*\(\s*id\s*\)\s*=>\s*\{\s*const\s+song\s*=\s*userData\?\.songs\.find\(\s*\(\s*song\s*\)\s=>\s*song\.id\s===\s*id\s*\);?/)
assert.match(code, /const\s+playSong\s*=\s*\(\s*id\s*\)\s*=>\s*\{\s*const\s+song\s*=\s*userData\?\.songs\.find\(\s*\(\s*song\s*\)\s*=>\s*song\.id\s*===\s*id\s*\);?/)
```
You should set `audio.src` to `song.src`.
```js
assert.match(code, /const\s+playSong\s*=\s*\(\s*id\s*\)\s*=>\s*\{\s*const\s+song\s*=\s*userData\?\.songs\.find\(\s*\(\s*song\s*\)\s=>\s*song\.id\s===\s*id\s*\);?\s*audio\.src\s*=\s*song\.src;?/)
assert.match(code, /const\s+playSong\s*=\s*\(\s*id\s*\)\s*=>\s*\{\s*const\s+song\s*=\s*userData\?\.songs\.find\(\s*\(\s*song\s*\)\s=>\s*song\.id\s*===\s*id\s*\);?\s*audio\.src\s*=\s*song\.src;?/)
```
You should set `audio.title` to `song.title`.

View File

@@ -14,7 +14,7 @@ Inside that array, add a boolean expression that checks if the player's `x` posi
You should have a boolean expression that checks if the player's `x` position is greater than or equal to the platform's `x` position minus half of the player's width.
```js
assert.match(code, /const\s+platformDetectionRules\s+=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,?\s*\]\s*;?/)
assert.match(code, /const\s+platformDetectionRules\s*=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,?\s*\]\s*;?/)
```
# --seed--

View File

@@ -14,7 +14,7 @@ Below that boolean expression, add another boolean expression that checks if the
You should have a boolean expression that checks if the player's `x` position is less than or equal to the sum of the platform's `x` position and the platform's width minus one third of the player's width.
```js
assert.match(code, /const\s+platformDetectionRules\s+=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,\s*player\.position\.x\s*<=\s*platform\.position\.x\s*\+\s*platform\.width\s*-\s*player\.width\s*\/\s*3\s*,?\s*\]\s*;?/)
assert.match(code, /const\s+platformDetectionRules\s*=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,\s*player\.position\.x\s*<=\s*platform\.position\.x\s*\+\s*platform\.width\s*-\s*player\.width\s*\/\s*3\s*,?\s*\]\s*;?/)
```
# --seed--

View File

@@ -16,21 +16,21 @@ Below that, add another boolean expression that checks if the player's `y` posit
You should not alter the existing `platformDetectionRules` array and its content.
```js
assert.match(code, /const\s+platformDetectionRules\s+=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,\s*player\.position\.x\s*<=\s*platform\.position\.x\s*\+\s*platform\.width\s*-\s*player\.width\s*\/\s*3\s*,\s*.*\s*.*\s*\]\s*;?/)
assert.match(code, /const\s+platformDetectionRules\s*=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,\s*player\.position\.x\s*<=\s*platform\.position\.x\s*\+\s*platform\.width\s*-\s*player\.width\s*\/\s*3\s*,\s*.*\s*.*\s*\]\s*;?/)
```
You should have a boolean expression that checks if the player's `y` position plus the player's height is greater than or equal to the platform's `y` position.
```js
assert.match(code, /const\s+platformDetectionRules\s+=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,\s*player\.position\.x\s*<=\s*platform\.position\.x\s*\+\s*platform\.width\s*-\s*player\.width\s*\/\s*3\s*,\s*player\.position\.y\s*\+\s*player\.height\s*>=\s*platform\.position\.y\s*,\s*.*\s*\]\s*;?/)
assert.match(code, /const\s+platformDetectionRules\s*=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,\s*player\.position\.x\s*<=\s*platform\.position\.x\s*\+\s*platform\.width\s*-\s*player\.width\s*\/\s*3\s*,\s*player\.position\.y\s*\+\s*player\.height\s*>=\s*platform\.position\.y\s*,\s*.*\s*\]\s*;?/)
```
You should have a boolean expression that checks if the player's `y` position is less than or equal to the sum of the platform's `y` position plus the platform's height.
```js
assert.match(code, /const\s+platformDetectionRules\s+=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,\s*player\.position\.x\s*<=\s*platform\.position\.x\s*\+\s*platform\.width\s*-\s*player\.width\s*\/\s*3\s*,\s*player\.position\.y\s*\+\s*player\.height\s*>=\s*platform\.position\.y\s*,\s*player\.position\.y\s*<=\s*platform\.position\.y\s*\+\s*platform\.height\s*,?\s*\]\s*;?/)
assert.match(code, /const\s+platformDetectionRules\s*=\s*\[\s*player\.position\.x\s*>=\s*platform\.position\.x\s*-\s*player\.width\s*\/\s*2\s*,\s*player\.position\.x\s*<=\s*platform\.position\.x\s*\+\s*platform\.width\s*-\s*player\.width\s*\/\s*3\s*,\s*player\.position\.y\s*\+\s*player\.height\s*>=\s*platform\.position\.y\s*,\s*player\.position\.y\s*<=\s*platform\.position\.y\s*\+\s*platform\.height\s*,?\s*\]\s*;?/)
```

View File

@@ -22,13 +22,13 @@ assert.match(code, /const\s+addOrUpdateTask\s*=\s*\(\s*\)\s*=>\s*\{\s*/)
You should move the `dataArrIndex` variable into the `addOrUpdateTask` function.
```js
assert.match(code, /const\s+addOrUpdateTask\s*=\s*\(\s*\)\s*=>\s*\{\s*const\s+dataArrIndex\s*=\s*taskData\.findIndex\(\s*(\(\s*item\s*\)|item)\s*=>\s*(item\.id\s===\s*currentTask\.id|currentTask\.id\s*===\s*item\.id)\s*\);?/)
assert.match(code, /const\s+addOrUpdateTask\s*=\s*\(\s*\)\s*=>\s*\{\s*const\s+dataArrIndex\s*=\s*taskData\.findIndex\(\s*(\(\s*item\s*\)|item)\s*=>\s*(item\.id\s*===\s*currentTask\.id|currentTask\.id\s*===\s*item\.id)\s*\);?/)
```
You should move the `taskObj` object into the `addOrUpdateTask` function.
```js
assert.match(code, /const\s+addOrUpdateTask\s*=\s*\(\s*\)\s*=>\s*\{\s*const\s+dataArrIndex\s*=\s*taskData\.findIndex\(\s*(?:\(\s*item\s*\)|item)\s*=>\s*(?:item\.id\s===\s*currentTask\.id|currentTask\.id\s*===\s*item\.id)\s*\)\s*;?\s*const\s+taskObj\s*=\s*\{\s*id\s*:\s*`\$\{\s*titleInput\.value\.toLowerCase\(\s*\)\.split\(\s*('|")\s{1}\1\s*\)\.join\(\s*('|")-\2\s*\)\s*\}-\$\{\s*Date\.now\(\s*\)\s*\}`\s*,\s*title\s*:\s*titleInput\.value\s*,\s*date\s*:\s*dateInput\.value\s*,\s*description\s*:\s*descriptionInput\.value\s*,?\s*\}\s*;?/)
assert.match(code, /const\s+addOrUpdateTask\s*=\s*\(\s*\)\s*=>\s*\{\s*const\s+dataArrIndex\s*=\s*taskData\.findIndex\(\s*(?:\(\s*item\s*\)|item)\s*=>\s*(?:item\.id\s*===\s*currentTask\.id|currentTask\.id\s*===\s*item\.id)\s*\)\s*;?\s*const\s+taskObj\s*=\s*\{\s*id\s*:\s*`\$\{\s*titleInput\.value\.toLowerCase\(\s*\)\.split\(\s*('|")\s{1}\1\s*\)\.join\(\s*('|")-\2\s*\)\s*\}-\$\{\s*Date\.now\(\s*\)\s*\}`\s*,\s*title\s*:\s*titleInput\.value\s*,\s*date\s*:\s*dateInput\.value\s*,\s*description\s*:\s*descriptionInput\.value\s*,?\s*\}\s*;?/)
```
You should move the `if` statement with the condition `dataArrIndex === -1` into your `addOrUpdateTask` function.

View File

@@ -28,13 +28,13 @@ assert.match(code, /const\s+editTask\s*=\s*\(\s*buttonEl\s*\)\s*=>\s*\{\s*const\
You should pass in `item` as the parameter of the `findIndex()` arrow function callback. Don't use curly braces.
```js
assert.match(code, /const\s+editTask\s+=\s*\(\s*buttonEl\s*\)\s*=>\s*\{\s*const\s+dataArrIndex\s*=\s*taskData\.findIndex\(\s*(\(\s*item\s*\)|item)/)
assert.match(code, /const\s+editTask\s*=\s*\(\s*buttonEl\s*\)\s*=>\s*\{\s*const\s+dataArrIndex\s*=\s*taskData\.findIndex\(\s*(\(\s*item\s*\)|item)/)
```
Your arrow function callback should check if `item.id === buttonEl.parentElement.id`.
```js
assert.match(code, /const\s+editTask\s+=\s*\(\s*buttonEl\s*\)\s*=>\s*\{\s*const\s+dataArrIndex\s*=\s*taskData\.findIndex\(\s*(\(\s*item\s*\)|item)\s*=>\s*(item\.id\s*===\s*buttonEl\.parentElement\.id|buttonEl\.partentElement\.id\s*===\s*item\.id)\s*\);?\s*\};?/)
assert.match(code, /const\s+editTask\s*=\s*\(\s*buttonEl\s*\)\s*=>\s*\{\s*const\s+dataArrIndex\s*=\s*taskData\.findIndex\(\s*(\(\s*item\s*\)|item)\s*=>\s*(item\.id\s*===\s*buttonEl\.parentElement\.id|buttonEl\.parentElement\.id\s*===\s*item\.id)\s*\);?\s*\};?/)
```
# --seed--

View File

@@ -18,7 +18,7 @@ Start by getting the `#current-date` element using the `.getElementById()` metho
You should use `const` to declare a `currentDateParagraph` variable.
```js
assert.match(code, /const\s+currentDateParagraph\s+=/);
assert.match(code, /const\s+currentDateParagraph\s*=/);
```
You should use `document.getElementById()` to get the `#current-date` element.
@@ -30,7 +30,7 @@ assert.match(code, /document\.getElementById\(\s*('|"|`)current-date\1\s*\)/);
You should assign the `#current-date` element to your `currentDateParagraph` variable.
```js
assert(code.match(/const\s+currentDateParagraph\s+=\s+document\.getElementById\(\s*('|"|`)current-date\1\s*\)/g));
assert(code.match(/const\s+currentDateParagraph\s*=\s*document\.getElementById\(\s*('|"|`)current-date\1\s*\)/g));
```
# --seed--

View File

@@ -14,7 +14,7 @@ Use the `.getElementById()` method to get the `#date-options` element and use `c
You should use `const` to declare a `dateOptionsSelectElement` variable.
```js
assert.match(code, /const\s+dateOptionsSelectElement\s+=/);
assert.match(code, /const\s+dateOptionsSelectElement\s*=/);
```
You should use `document.getElementById()` to get the `#date-options` element.
@@ -26,7 +26,7 @@ assert.match(code, /document\.getElementById\(\s*('|"|`)date-options\1\s*\)/);
You should assign the `#date-options` element to your `dateOptionsSelectElement` variable.
```js
assert(code.match(/const\s+dateOptionsSelectElement\s+=\s+document\.getElementById\(\s*('|"|`)date-options\1\s*\)/g));
assert(code.match(/const\s+dateOptionsSelectElement\s*=\s*document\.getElementById\(\s*('|"|`)date-options\1\s*\)/g));
```
# --seed--

View File

@@ -26,13 +26,13 @@ Create a new `const` variable called `date` and assign it a `Date` object with `
You should use `const` to declare a `date` variable.
```js
assert.match(code, /const\s+date\s+=/);
assert.match(code, /const\s+date\s*=/);
```
You should assign a `Date` object to your `date` variable with `new Date()`.
```js
assert(code.match(/const\s+date\s+=\s+new\s+Date\(\s*\)/g));
assert(code.match(/const\s+date\s*=\s*new\s+Date\(\s*\)/g));
```
# --seed--

View File

@@ -24,13 +24,13 @@ Using `const`, create a variable named `day` and assign it the day of the month
You should use `const` to declare a `day` variable.
```js
assert.match(code, /const\s+day\s+=/);
assert.match(code, /const\s+day\s*=/);
```
You should assign the `date.getDate()` to your `day` variable.
```js
assert(code.match(/const\s+day\s+=\s+date\.getDate\(\s*\)/g));
assert(code.match(/const\s+day\s*=\s*date\.getDate\(\s*\)/g));
```
# --seed--

View File

@@ -18,13 +18,13 @@ Remember to add `1` to the number returned by `.getMonth()`.
You should use `const` to declare a `month` variable.
```js
assert.match(code, /const\s+month\s+=/);
assert.match(code, /const\s+month\s*=/);
```
You should assign the `date.getMonth() + 1` to your `month` variable.
```js
assert(code.match(/const\s+month\s+=\s+date\.getMonth\(\s*\)\s*\+\s*1/g));
assert(code.match(/const\s+month\s*=\s*date\.getMonth\(\s*\)\s*\+\s*1/g));
```
# --seed--

View File

@@ -16,13 +16,13 @@ Using `const`, create a variable named `year` and assign it the year from `date`
You should use `const` to declare a `year` variable.
```js
assert.match(code, /const\s+year\s+=/);
assert.match(code, /const\s+year\s*=/);
```
You should assign the `date.getFullYear()` to your `year` variable.
```js
assert(code.match(/const\s+year\s+=\s+date\.getFullYear\(\s*\)/g));
assert(code.match(/const\s+year\s*=\s*date\.getFullYear\(\s*\)/g));
```
# --seed--

View File

@@ -16,13 +16,13 @@ Create a `const` variable named `hours` and assign it the hour from `date` with
You should use `const` to declare a `hours` variable.
```js
assert.match(code, /const\s+hours\s+=/);
assert.match(code, /const\s+hours\s*=/);
```
You should assign the `date.getHours()` to your `hours` variable.
```js
assert(code.match(/const\s+hours\s+=\s+date\.getHours\(\s*\)/g));
assert(code.match(/const\s+hours\s*=\s*date\.getHours\(\s*\)/g));
```
# --seed--

View File

@@ -16,13 +16,13 @@ Create a `const` variable named `minutes` and assign it the minutes from `date`
You should use `const` to declare a `minutes` variable.
```js
assert.match(code, /const\s+minutes\s+=/);
assert.match(code, /const\s+minutes\s*=/);
```
You should assign the `date.getMinutes()` to your `minutes` variable.
```js
assert(code.match(/const\s+minutes\s+=\s+date\.getMinutes\(\s*\)/g));
assert(code.match(/const\s+minutes\s*=\s*date\.getMinutes\(\s*\)/g));
```
# --seed--

View File

@@ -14,7 +14,7 @@ Inside the template literal, add an embedded expression that contains the `day`
You should use the `day` constant inside the template literal.
```js
assert(code.match(/const\s+formattedDate\s+=\s+`\${day}`/g));
assert(code.match(/const\s+formattedDate\s*=\s*`\${day}`/g));
```
# --seed--

View File

@@ -14,7 +14,7 @@ After the `day` variable, add a dash (`-`) followed by another embedded expressi
You should add a dash followed by the `month` constant to the template literal.
```js
assert(code.match(/const\s+formattedDate\s+=\s+`\${day}\s*-\s*\${month}`/g));
assert(code.match(/const\s+formattedDate\s*=\s*`\${day}\s*-\s*\${month}`/g));
```
# --seed--

View File

@@ -14,7 +14,7 @@ After the `month` variable, add a dash followed by another embedded expression t
You should add a dash followed by the `year` constant to the template literal.
```js
assert(code.match(/const\s+formattedDate\s+=\s+`\${day}\s*-\s*\${month}\s*-\s*\${year}`/g));
assert(code.match(/const\s+formattedDate\s*=\s*`\${day}\s*-\s*\${month}\s*-\s*\${year}`/g));
```
# --seed--