diff --git a/curriculum/challenges/_meta/learn-form-validation-by-building-a-calorie-counter/meta.json b/curriculum/challenges/_meta/learn-form-validation-by-building-a-calorie-counter/meta.json index 70f761b7c58..21b5f162b4f 100644 --- a/curriculum/challenges/_meta/learn-form-validation-by-building-a-calorie-counter/meta.json +++ b/curriculum/challenges/_meta/learn-form-validation-by-building-a-calorie-counter/meta.json @@ -15,303 +15,376 @@ "Step 1" ], [ - "5ddb965c65d27e1512d44d9b", + "63b606f09a14cc1781aea1fb", "Step 2" ], [ - "5ddb965c65d27e1512d44d9c", + "63b6075a62883218d282504c", "Step 3" ], [ - "5ddb965c65d27e1512d44d9d", + "63b607af6fcdb119aae9b16a", "Step 4" ], [ - "5ddb965c65d27e1512d44d9e", + "63b60821c855d01b1eda3c0b", "Step 5" ], [ - "5ddb965c65d27e1512d44d9f", + "63b6088bb56e2d1cac364043", "Step 6" ], [ - "5ddb965c65d27e1512d44da0", + "63b608ebf40c871d960fc004", "Step 7" ], [ - "5ddb965c65d27e1512d44da1", + "63b60a140bf5a321d50a7315", "Step 8" ], [ - "5ddb965c65d27e1512d44da2", + "63b60aaaa65f8922bfce6b7e", "Step 9" ], [ - "5ddb965c65d27e1512d44da3", + "63b60af1a0b9f7238a9dd294", "Step 10" ], [ - "5ddb965c65d27e1512d44da4", + "63b60c09c5039f25a3b2dda9", "Step 11" ], [ - "5ddb965c65d27e1512d44da5", + "63b60ca38c897f2721b27959", "Step 12" ], [ - "5ddb965c65d27e1512d44da6", + "63b60cfaca25bb27edd40f62", "Step 13" ], [ - "5ddb965c65d27e1512d44da7", + "63b60d3c5048302906962231", "Step 14" ], [ - "5ddb965c65d27e1512d44da8", + "63b613f367584d2a5d041b7d", "Step 15" ], [ - "5ddb965c65d27e1512d44da9", + "63b61490e633a22b4593e62f", "Step 16" ], [ - "5ddb965c65d27e1512d44daa", + "63b614e6a1f7fe2cef6312dc", "Step 17" ], [ - "5ddb965c65d27e1512d44dab", + "63b6152e6aff882db819fc1e", "Step 18" ], [ - "5ddb965c65d27e1512d44dac", + "63b61584def8fa2ebcc259e0", "Step 19" ], [ - "5ddb965c65d27e1512d44dad", + "63bf43be3f969d24d4ed233c", "Step 20" ], [ - "5e302e80e003129199103c78", + "63bf446945d34d25e6db6e4f", "Step 21" ], [ - "5e302e8ce003129199103c79", + "63bf45ce0dc8d4270760c6d0", "Step 22" ], [ - "5ddb965c65d27e1512d44dae", + "63bf461011fca327d3b60fa8", "Step 23" ], [ - "5ddb965c65d27e1512d44daf", + "63bf47fd40599f29827f484d", "Step 24" ], [ - "5ddb965c65d27e1512d44db0", + "63bf492b6dfb292a79f0e675", "Step 25" ], [ - "5ddb965c65d27e1512d44db1", + "63bf4bfe9de3852be51c8f86", "Step 26" ], [ - "5ddb965c65d27e1512d44db2", + "63bf4d351e06432ce9bf3627", "Step 27" ], [ - "5ddb965c65d27e1512d44db3", + "63bf511b85b6082e54dc1573", "Step 28" ], [ - "5ddb965c65d27e1512d44db4", + "63bf5230bccd1c2f5c13e1ce", "Step 29" ], [ - "5ddb965c65d27e1512d44db5", + "63bf598a4c807930a13a1a27", "Step 30" ], [ - "5ddb965c65d27e1512d44db6", + "63bf5a518d54f63181ab639a", "Step 31" ], [ - "5ddb965c65d27e1512d44db7", + "63bf5a92fd148d3264d5322b", "Step 32" ], [ - "5ddb965c65d27e1512d44db8", + "63bf5adfe2981b332eb007b6", "Step 33" ], [ - "5ddb965c65d27e1512d44db9", + "63bf5bcfebff0734593fad19", "Step 34" ], [ - "5ddb965c65d27e1512d44dba", + "63bf5c438f523a359769106c", "Step 35" ], [ - "5ddb965c65d27e1512d44dbb", + "63bf5cf03b50bf36cfbe94ea", "Step 36" ], [ - "5ddb965c65d27e1512d44dbc", + "63c1dfbd56c71e278800010c", "Step 37" ], [ - "5ddb965c65d27e1512d44dbd", + "63c1e0af28078f2dfad9eb3e", "Step 38" ], [ - "5ddb965c65d27e1512d44dbe", + "63c1e1965a898d302e0af4e3", "Step 39" ], [ - "5ddb965c65d27e1512d44dbf", + "63c1e5b4b3c8a031def3bd65", "Step 40" ], [ - "5ddb965c65d27e1512d44dc0", + "63c1e704ee12703347625900", "Step 41" ], [ - "5ddb965c65d27e1512d44dc1", + "63c2164c0df38a382062c4af", "Step 42" ], [ - "5ddb965c65d27e1512d44dc2", + "63c216da562fbb3957b9cb2c", "Step 43" ], [ - "5ddb965c65d27e1512d44dc3", + "63c2171c1e5b6e3aa51768d0", "Step 44" ], [ - "5ddb965c65d27e1512d44dc4", + "63c21774193de43bbc6a769f", "Step 45" ], [ - "5ddb965c65d27e1512d44dc5", + "63c217ccd939053ce4fa16d6", "Step 46" ], [ - "5ddb965c65d27e1512d44dc6", + "63c21839f56eaf3ef4e027c4", "Step 47" ], [ - "5ddb965c65d27e1512d44dc7", + "63c2187f55eb0f400269568f", "Step 48" ], [ - "5ddb965c65d27e1512d44dc8", + "63c218c028c56a411b2a379a", "Step 49" ], [ - "5ddb965c65d27e1512d44dc9", + "63c21dea919c8e4adb0df8e8", "Step 50" ], [ - "5ddb965c65d27e1512d44dca", + "63c2194dce265f429300c8b1", "Step 51" ], [ - "5ddb965c65d27e1512d44dcb", + "63c21c17fa8fd6447ff0389d", "Step 52" ], [ - "5ddb965c65d27e1512d44dcc", + "63c21cd2c34541469f5700a9", "Step 53" ], [ - "5ddb965c65d27e1512d44dcd", + "63c21d4f48267a47c2946788", "Step 54" ], [ - "5ddb965c65d27e1512d44dce", + "63c8ab51214c8c1f1b9a49f7", "Step 55" ], [ - "5ddb965c65d27e1512d44dcf", + "63c8ad0cd8f1e5201c4ef2e4", "Step 56" ], [ - "5ddb965c65d27e1512d44dd0", + "63c8b0187cceff21c8389543", "Step 57" ], [ - "5ddb965c65d27e1512d44dd1", + "63c8be904ffff922f3c6f8d0", "Step 58" ], [ - "5ddb965c65d27e1512d44dd2", + "63c8c00bfb671b23f9de4159", "Step 59" ], [ - "5ddb965c65d27e1512d44dd3", + "63c8c15fd337ad24b9b68049", "Step 60" ], [ - "5ddb965c65d27e1512d44dd4", + "63c9bc53735149084390e5d0", "Step 61" ], [ - "5ddb965c65d27e1512d44dd5", + "63c9bcc26219e7090da0f549", "Step 62" ], [ - "5ddb965c65d27e1512d44dd6", + "63c9bce376ca4f09c15a3768", "Step 63" ], [ - "5ddb965c65d27e1512d44dd7", + "63c9bdd916e0c10af01ed8d7", "Step 64" ], [ - "5ddb965c65d27e1512d44dd8", + "63c9be334f4a050c0b94bc93", "Step 65" ], [ - "5ddb965c65d27e1512d44dd9", + "63c9bef7fec05c0d38853828", "Step 66" ], [ - "5ddb965c65d27e1512d44dda", + "63c9bf80558d780e848b2987", "Step 67" ], [ - "5ddb965c65d27e1512d44ddb", + "63c9c09a7daa4f0ff92c4023", "Step 68" ], [ - "5ddb965c65d27e1512d44ddc", + "63c9c0d0857f0a10a57af936", "Step 69" ], [ - "5ddb965c65d27e1512d44ddd", + "63c9c11a0a090311dff55564", "Step 70" ], [ - "5ddb965c65d27e1512d44dde", + "63c9c16dd75dd212dc12363c", "Step 71" ], [ - "5ddb965c65d27e1512d44ddf", + "63c9c1ef134f3513e751c975", "Step 72" ], [ - "5ddb965c65d27e1512d44de0", + "63c9e3a83bb3e61a80eea564", "Step 73" ], [ - "5ddb965c65d27e1512d44de1", + "63c9e45519caf31b987fbb5f", "Step 74" ], [ - "5ddb965c65d27e1512d44de2", + "63c9e4d2ff41811dd640504f", "Step 75" ], [ - "5ddb965c65d27e1512d44de3", + "63c9e51b3a007a1eba1cd0f6", "Step 76" + ], + [ + "63c9e55b4b06c11fff555c64", + "Step 77" + ], + [ + "63c9e5eea8261d22856ead1c", + "Step 78" + ], + [ + "63c9e63bb1e32d23b6adbe44", + "Step 79" + ], + [ + "63c9e6b7c0303524af2d0bc2", + "Step 80" + ], + [ + "63c9e769df38c92635c158ba", + "Step 81" + ], + [ + "63c9e7d5b21eee2776ecc226", + "Step 82" + ], + [ + "63c9e84c9fe8ca28c4101189", + "Step 83" + ], + [ + "63c9e8fe3a6f022a05a04675", + "Step 84" + ], + [ + "63c9e94e9df7d72aed1c24bd", + "Step 85" + ], + [ + "63c9ea23dbadbf2c2764e3f5", + "Step 86" + ], + [ + "63c9ea9b16430f2d54522464", + "Step 87" + ], + [ + "63c9eb09bcfaa72e3da820a1", + "Step 88" + ], + [ + "63c9eb4a5d68f12f32d9b440", + "Step 89" + ], + [ + "63c9ebb7b12bca3025b0a935", + "Step 90" + ], + [ + "63c9ec044acedf312c4974ff", + "Step 91" + ], + [ + "63c9f24afbc9cf324dcaa9a4", + "Step 92" + ], + [ + "63c9f28bda3e3f336e21b6b4", + "Step 93" + ], + [ + "63c9f2bff625af342023512c", + "Step 94" ] - ]} + ] +} \ No newline at end of file diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/5ddb965c65d27e1512d44d9a.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/5ddb965c65d27e1512d44d9a.md new file mode 100644 index 00000000000..c3def32154d --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/5ddb965c65d27e1512d44d9a.md @@ -0,0 +1,122 @@ +--- +id: 5ddb965c65d27e1512d44d9a +title: Step 1 +challengeType: 0 +dashedName: step-1 +--- + +# --description-- + +You have been provided with boilerplate CSS and HTML. However, you need to build your calorie counter form. + +Feel free to explore the HTML and CSS, then add a `form` element and give it an `id` set to `calorie-counter`. + +# --hints-- + +You should have a `form` element. + +```js +assert.exists(document.querySelector('form')); +``` + +Your `form` element should have an `id` attribute set to `calorie-counter`. + +```js +assert.equal(document.querySelector('form')?.id, 'calorie-counter'); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+--fcc-editable-region-- + +--fcc-editable-region-- +
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b606f09a14cc1781aea1fb.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b606f09a14cc1781aea1fb.md new file mode 100644 index 00000000000..e938bc8c2e3 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b606f09a14cc1781aea1fb.md @@ -0,0 +1,146 @@ +--- +id: 63b606f09a14cc1781aea1fb +title: Step 2 +challengeType: 0 +dashedName: step-2 +--- + +# --description-- + +Create a `label` element, give it a `for` attribute set to `budget` and the text `Budget`, then create an `input` element with the `id` set to `budget`. + +# --hints-- + +You should create a `label` element in your `form`. + +```js +assert.exists(document.querySelector('form label')); +``` + +Your `label` element should have a `for` attribute set to `budget`. + +```js +assert.equal(document.querySelector('form label')?.getAttribute('for'), 'budget'); +``` + +Your `label` element should have the text `Budget`. + +```js +assert.equal(document.querySelector('form label')?.innerText, 'Budget'); +``` + +You should create an `input` element within your `form`. + +```js +assert.exists(document.querySelector('form input')); +``` + +Your `input` element should come after your `label` element. + +```js +assert.equal(document.querySelector('form input')?.previousElementSibling?.tagName, "LABEL"); +``` + +Your `input` element should have an `id` set to `budget`. + +```js +assert.equal(document.querySelector('form input')?.id, "budget"); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+--fcc-editable-region-- +
+ +
+--fcc-editable-region-- +
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b6075a62883218d282504c.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b6075a62883218d282504c.md new file mode 100644 index 00000000000..fcabad47a30 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b6075a62883218d282504c.md @@ -0,0 +1,131 @@ +--- +id: 63b6075a62883218d282504c +title: Step 3 +challengeType: 0 +dashedName: step-3 +--- + +# --description-- + +Your `input` element needs some additional attributes. Give it a `type` set to `number` to only allow numeric inputs, a `min` attribute set to `0` to only allow positive numbers, and a `placeholder` set to `Daily calorie budget`. + +Finally, mark the `input` element as `required`. + +# --hints-- + +Your `input` element should have a `type` attribute set to `number`. + +```js +assert.equal(document.querySelector('form input').type, 'number'); +``` + +Your `input` element should have a `min` attribute set to `0`. + +```js +assert.equal(document.querySelector('form input').min, '0'); +``` + +Your `input` element should have a `placeholder` attribute set to `Daily calorie budget`. + +```js +assert.equal(document.querySelector('form input').placeholder, 'Daily calorie budget'); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+--fcc-editable-region-- +
+ + +
+--fcc-editable-region-- +
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b607af6fcdb119aae9b16a.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b607af6fcdb119aae9b16a.md new file mode 100644 index 00000000000..5079bde79a8 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b607af6fcdb119aae9b16a.md @@ -0,0 +1,168 @@ +--- +id: 63b607af6fcdb119aae9b16a +title: Step 4 +challengeType: 0 +dashedName: step-4 +--- + +# --description-- + +Create a `fieldset` element with the `id` set to `breakfast`. + +Within that element, create a `legend` with the text `Breakfast`, and an empty `div` with the `class` set to `input-container`. + +# --hints-- + +You should create a `fieldset` element in your `form`. + +```js +assert.exists(document.querySelector('form fieldset')); +``` + +Your `fieldset` element should come after your `input` element. + +```js +assert.equal(document.querySelector('form fieldset')?.previousElementSibling?.tagName, "INPUT"); +``` + +Your `fieldset` element should have an `id` set to `breakfast`. + +```js +assert.equal(document.querySelector('form fieldset')?.id, "breakfast"); +``` + +You should create a `legend` element within your `fieldset`. + +```js +assert.exists(document.querySelector('form fieldset legend')); +``` + +Your `legend` element should have the text `Breakfast`. + +```js +assert.equal(document.querySelector('form fieldset legend')?.innerText, "Breakfast"); +``` + +You should create a `div` element within your `fieldset`. + +```js +assert.exists(document.querySelector('form fieldset div')); +``` + +Your `div` element should come after your `legend` element. + +```js +assert.equal(document.querySelector('form fieldset div')?.previousElementSibling?.tagName, "LEGEND"); +``` + +Your `div` element should have a `class` set to `input-container`. + +```js +assert.equal(document.querySelector('form fieldset div')?.className, "input-container"); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +--fcc-editable-region-- + +--fcc-editable-region-- +
+
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60821c855d01b1eda3c0b.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60821c855d01b1eda3c0b.md new file mode 100644 index 00000000000..7de68f5215c --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60821c855d01b1eda3c0b.md @@ -0,0 +1,164 @@ +--- +id: 63b60821c855d01b1eda3c0b +title: Step 5 +challengeType: 0 +dashedName: step-5 +--- + +# --description-- + +Now create a `fieldset` with an `id` set to `lunch`, and a corresponding `legend` and `div` element. + +# --hints-- + +You should create a second `fieldset` element in your `form`. + +```js +assert.exists(document.querySelectorAll('form fieldset')[1]); +``` + +Your second `fieldset` element should come after your first `fieldset` element. + +```js +assert.equal(document.querySelectorAll('form fieldset')[1]?.previousElementSibling?.tagName, "FIELDSET"); +``` + +Your second `fieldset` element should have an `id` set to `lunch`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[1]?.id, "lunch"); +``` + +Your second `fieldset` element should contain a `legend` element. + +```js +assert.exists(document.querySelectorAll('form fieldset')[1]?.querySelector('legend')); +``` + +Your new `legend` element should have the text `Lunch`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[1]?.querySelector('legend')?.innerText, "Lunch"); +``` + +Your second `fieldset` element should contain a `div` element. + +```js +assert.exists(document.querySelectorAll('form fieldset')[1]?.querySelector('div')); +``` + +Your new `div` element should have a `class` set to `input-container`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[1]?.querySelector('div')?.className, "input-container"); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+--fcc-editable-region-- + +--fcc-editable-region-- +
+
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b6088bb56e2d1cac364043.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b6088bb56e2d1cac364043.md new file mode 100644 index 00000000000..f7c617f998e --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b6088bb56e2d1cac364043.md @@ -0,0 +1,168 @@ +--- +id: 63b6088bb56e2d1cac364043 +title: Step 6 +challengeType: 0 +dashedName: step-6 +--- + +# --description-- + +Continuing the pattern, create a `fieldset` for `dinner` with the same nested elements. + +# --hints-- + +You should create a third `fieldset` element in your `form`. + +```js +assert.exists(document.querySelectorAll('form fieldset')[2]); +``` + +Your third `fieldset` element should come after your second `fieldset` element. + +```js +assert.equal(document.querySelectorAll('form fieldset')[2]?.previousElementSibling?.tagName, "FIELDSET"); +``` + +Your third `fieldset` element should have an `id` set to `dinner`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[2]?.id, "dinner"); +``` + +Your third `fieldset` element should contain a `legend` element. + +```js +assert.exists(document.querySelectorAll('form fieldset')[2]?.querySelector('legend')); +``` + +Your new `legend` element should have the text `Dinner`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[2]?.querySelector('legend')?.innerText, "Dinner"); +``` + +Your third `fieldset` element should contain a `div` element. + +```js +assert.exists(document.querySelectorAll('form fieldset')[2]?.querySelector('div')); +``` + +Your new `div` element should have a `class` set to `input-container`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[2]?.querySelector('div')?.className, "input-container"); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+--fcc-editable-region-- + +--fcc-editable-region-- +
+
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b608ebf40c871d960fc004.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b608ebf40c871d960fc004.md new file mode 100644 index 00000000000..911126b33e4 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b608ebf40c871d960fc004.md @@ -0,0 +1,214 @@ +--- +id: 63b608ebf40c871d960fc004 +title: Step 7 +challengeType: 0 +dashedName: step-7 +--- + +# --description-- + +You need two more of these `fieldset` code blocks – one for `snacks` and one for `exercise`. + +# --hints-- + +You should create a fourth `fieldset` element in your `form`. + +```js +assert.exists(document.querySelectorAll('form fieldset')[3]); +``` + +Your fourth `fieldset` element should come after your third `fieldset` element. + +```js +assert.equal(document.querySelectorAll('form fieldset')[3]?.previousElementSibling?.tagName, "FIELDSET"); +``` + +Your fourth `fieldset` element should have an `id` set to `snacks`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[3]?.id, "snacks"); +``` + +Your fourth `fieldset` element should contain a `legend` element. + +```js +assert.exists(document.querySelectorAll('form fieldset')[3]?.querySelector('legend')); +``` + +Your fourth `legend` element should have the text `Snacks`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[3]?.querySelector('legend')?.innerText, "Snacks"); +``` + +Your fourth `fieldset` element should contain a `div` element. + +```js +assert.exists(document.querySelectorAll('form fieldset')[3]?.querySelector('div')); +``` + +Your fifth `div` element should have a `class` set to `input-container`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[3]?.querySelector('div')?.className, "input-container"); +``` + +You should create a fifth `fieldset` element in your `form`. + +```js +assert.exists(document.querySelectorAll('form fieldset')[4]); +``` + +Your fifth `fieldset` element should come after your fourth `fieldset` element. + +```js +assert.equal(document.querySelectorAll('form fieldset')[4]?.previousElementSibling?.tagName, "FIELDSET"); +``` + +Your fifth `fieldset` element should have an `id` set to `exercise`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[4]?.id, "exercise"); +``` + +Your fifth `fieldset` element should contain a `legend` element. + +```js +assert.exists(document.querySelectorAll('form fieldset')[4]?.querySelector('legend')); +``` + +Your fifth `legend` element should have the text `Exercise`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[4]?.querySelector('legend')?.innerText, "Exercise"); +``` + +Your fifth `fieldset` element should contain a `div` element. + +```js +assert.exists(document.querySelectorAll('form fieldset')[4]?.querySelector('div')); +``` + +Your fifth `div` element should have a `class` set to `input-container`. + +```js +assert.equal(document.querySelectorAll('form fieldset')[4]?.querySelector('div')?.className, "input-container"); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+--fcc-editable-region-- + +--fcc-editable-region-- +
+
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60a140bf5a321d50a7315.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60a140bf5a321d50a7315.md new file mode 100644 index 00000000000..068bea72dfc --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60a140bf5a321d50a7315.md @@ -0,0 +1,163 @@ +--- +id: 63b60a140bf5a321d50a7315 +title: Step 8 +challengeType: 0 +dashedName: step-8 +--- + +# --description-- + +Create a `div` and give it a `class` set to `controls`. Nest a `span` element within that `div`. + +# --hints-- + +You should create a new `div` element in your `form`. + +```js +assert.exists(document.querySelector('form > div')); +``` + +Your `div` element should come after your `fieldset` elements. + +```js +assert.equal(document.querySelector('form > div')?.previousElementSibling?.tagName, "FIELDSET"); +assert.notExists(document.querySelector('form > div')?.nextElementSibling); +``` + +Your `div` element should have a `class` attribute set to `controls`. + +```js +assert.equal(document.querySelector('form > div')?.className, "controls"); +``` + +You should nest a `span` element within your `div`. + +```js +assert.exists(document.querySelector('form > div > span')); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+--fcc-editable-region-- + +--fcc-editable-region-- +
+
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60aaaa65f8922bfce6b7e.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60aaaa65f8922bfce6b7e.md new file mode 100644 index 00000000000..c9723d26fcb --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60aaaa65f8922bfce6b7e.md @@ -0,0 +1,210 @@ +--- +id: 63b60aaaa65f8922bfce6b7e +title: Step 9 +challengeType: 0 +dashedName: step-9 +--- + +# --description-- + +In your `span` element, create a `label` element for an `entry-dropdown` and give it the text `Add food or exercise:`. Then create a `select` element with the `id` set to `entry-dropdown` and a `name` set to `options`. Below that, add a `button` element with the `id` set to `add-entry` and the text `Add Entry`. + +Give your `button` element a `type` attribute set to `button` to prevent automatic form submission. + +# --hints-- + +You should add a `label` element to your `span` element. + +```js +assert.exists(document.querySelector('.controls > span > label')); +``` + +Your new `label` element should have a `for` attribute set to `entry-dropdown`. + +```js +assert.equal(document.querySelector('.controls > span > label')?.getAttribute('for'), 'entry-dropdown'); +``` + +Your new `label` element should have the text `Add food or exercise:`. + +```js +assert.equal(document.querySelector('.controls > span > label')?.innerText, 'Add food or exercise:'); +``` + +You should add a `select` element to your `span` element. + +```js +assert.exists(document.querySelector('.controls > span > select')); +``` + +Your `select` element should come after your `label` element. + +```js +assert(document.querySelector('.controls > span > select')?.previousElementSibling?.tagName === 'LABEL'); +``` + +Your new `select` element should have an `id` attribute set to `entry-dropdown`. + +```js +assert.equal(document.querySelector('.controls > span > select')?.getAttribute('id'), 'entry-dropdown'); +``` + +Your new `select` element should have a `name` attribute set to `options`. + +```js +assert.equal(document.querySelector('.controls > span > select')?.getAttribute('name'), 'options'); +``` + +You should add a `button` element to your `span` element. + +```js +assert.exists(document.querySelector('.controls > span > button')); +``` + +Your `button` element should come after your `select` element. + +```js +assert(document.querySelector('.controls > span > button')?.previousElementSibling?.tagName === 'SELECT'); +``` + +Your new `button` element should have an `id` attribute set to `add-entry`. + +```js +assert.equal(document.querySelector('.controls > span > button')?.getAttribute('id'), 'add-entry'); +``` + +Your new `button` element should have the text `Add Entry`. + +```js +assert.equal(document.querySelector('.controls > span > button')?.innerText, 'Add Entry'); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+--fcc-editable-region-- +
+ + + +
+--fcc-editable-region-- +
+
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60af1a0b9f7238a9dd294.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60af1a0b9f7238a9dd294.md new file mode 100644 index 00000000000..27f69a473d9 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60af1a0b9f7238a9dd294.md @@ -0,0 +1,220 @@ +--- +id: 63b60af1a0b9f7238a9dd294 +title: Step 10 +challengeType: 0 +dashedName: step-10 +--- + +# --description-- + +Your select menu needs options for each of the food and exercise `fieldset` elements you created in the previous steps. Use the `option` element to create a new option for each `fieldset`. The `value` attribute of each option should be the `id` of the `fieldset`, and the text of each option should be the text of the `legend`. + +Set the `Breakfast` option as the `selected` option. + +# --hints-- + +You should create five `option` elements within your `select` element. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.length, 5); +``` + +Your first `option` should have the text `Breakfast`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[0]?.textContent, 'Breakfast'); +``` + +Your first `option` should have the `value` attribute set to `breakfast`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[0]?.value, 'breakfast'); +``` + +Your second `option` should have the text `Lunch`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[1]?.textContent, 'Lunch'); +``` + +Your second `option` should have the `value` attribute set to `lunch`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[1]?.value, 'lunch'); +``` + +Your third `option` should have the text `Dinner`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[2]?.textContent, 'Dinner'); +``` + +Your third `option` should have the `value` attribute set to `dinner`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[2]?.value, 'dinner'); +``` + +Your fourth `option` should have the text `Snacks`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[3]?.textContent, 'Snacks'); +``` + +Your fourth `option` should have the `value` attribute set to `snacks`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[3]?.value, 'snacks'); +``` + +Your fifth `option` should have the text `Exercise`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[4]?.textContent, 'Exercise'); +``` + +Your fifth `option` should have the `value` attribute set to `exercise`. + +```js +assert.equal(document.querySelectorAll('.controls select option')?.[4]?.value, 'exercise'); +``` + +Your first `option` should be selected by default. + +```js +assert.isTrue(document.querySelectorAll('.controls select option')?.[0]?.getAttributeNames()?.includes('selected')); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+--fcc-editable-region-- +
+ + + + + +
+--fcc-editable-region-- +
+
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60c09c5039f25a3b2dda9.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60c09c5039f25a3b2dda9.md new file mode 100644 index 00000000000..4e28d650816 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60c09c5039f25a3b2dda9.md @@ -0,0 +1,207 @@ +--- +id: 63b60c09c5039f25a3b2dda9 +title: Step 11 +challengeType: 0 +dashedName: step-11 +--- + +# --description-- + +Create another `div` element. Within it, nest a `button` to `submit` the form, with an `id` set to `calculate-calories`. This button should have the text `Calculate Remaining Calories`. + +Then add a `button` with the `id` set to `clear` to clear the form (don't forget to give it a `type` attribute that prevents it from submitting the form). This button needs the text `Clear`. + +# --hints-- + +You should create a second `div` element. + +```js +assert.equal(document.querySelectorAll('form > div')?.length, 2); +``` + +Your new `div` element should have a `button` element. + +```js +assert.exists(document.querySelectorAll('form > div')?.[1]?.querySelector('button')); +``` + +Your `button` element should have a `type` attribute set to `submit`. + +```js +assert.equal(document.querySelectorAll('form > div')?.[1]?.querySelector('button')?.getAttribute('type'), 'submit'); +``` + +Your `button` element should have an `id` attribute set to `calculate-calories`. + +```js +assert.equal(document.querySelectorAll('form > div')?.[1]?.querySelector('button')?.getAttribute('id'), 'calculate-calories'); +``` + +Your `button` element should have the text `Calculate Remaining Calories`. + +```js +assert.equal(document.querySelectorAll('form > div')?.[1]?.querySelector('button')?.innerText, 'Calculate Remaining Calories'); +``` + +Your `div` element should have a second `button` element. + +```js +assert.exists(document.querySelectorAll('form > div')?.[1]?.querySelectorAll('button')?.[1]); +``` + +Your second `button` element should have a `type` attribute set to `button`. + +```js +assert.equal(document.querySelectorAll('form > div')?.[1]?.querySelectorAll('button')?.[1]?.getAttribute('type'), 'button'); +``` + +Your second `button` element should have an `id` attribute set to `clear`. + +```js +assert.equal(document.querySelectorAll('form > div')?.[1]?.querySelectorAll('button')?.[1]?.getAttribute('id'), 'clear'); +``` + +Your second `button` element should have the text `Clear`. + +```js +assert.equal(document.querySelectorAll('form > div')?.[1]?.querySelectorAll('button')?.[1]?.innerText, 'Clear'); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+--fcc-editable-region-- + +--fcc-editable-region-- +
+
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60ca38c897f2721b27959.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60ca38c897f2721b27959.md new file mode 100644 index 00000000000..aaf24c8d8cb --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60ca38c897f2721b27959.md @@ -0,0 +1,182 @@ +--- +id: 63b60ca38c897f2721b27959 +title: Step 12 +challengeType: 0 +dashedName: step-12 +--- + +# --description-- + +Your form needs somewhere to display the results. Add an empty `div` element and give it an `id` of `output` and the `class` values of `output` and `hide`. + +# --hints-- + +You should add a `div` element after your `form`. + +```js +assert.exists(document.querySelector('.container > div')); +``` + +Your new `div` element should have an `id` set to `output`. + +```js +assert.equal(document.querySelector('.container > div')?.id, 'output'); +``` + +Your new `div` element should have the `class` values of `output` and `hide`. + +```js +assert.include(document.querySelector('.container > div')?.className.split(/\s+/), 'output'); +assert.include(document.querySelector('.container > div')?.className.split(/\s+/), 'hide'); +``` + +Your new `div` should be empty. + +```js +assert.equal(document.querySelector('.container > div')?.innerHTML, ''); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+--fcc-editable-region-- + +--fcc-editable-region-- +
+
+ + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60cfaca25bb27edd40f62.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60cfaca25bb27edd40f62.md new file mode 100644 index 00000000000..17934b0039d --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60cfaca25bb27edd40f62.md @@ -0,0 +1,170 @@ +--- +id: 63b60cfaca25bb27edd40f62 +title: Step 13 +challengeType: 0 +dashedName: step-13 +--- + +# --description-- + +Finally, you need to link your JavaScript file to your HTML. Create a `script` element to do so. + +# --hints-- + +You should have a `script` element. + +```js +assert.isAtLeast(document.querySelectorAll('script')?.length, 1); +``` + +Your `script` element should have the `src` set to `./script.js`. + +```js +assert.match(code, /script\s*?src\s*?=\s*?('|")(\.\/)?script\.js\1/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+--fcc-editable-region-- + +--fcc-editable-region-- + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js + +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60d3c5048302906962231.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60d3c5048302906962231.md new file mode 100644 index 00000000000..de3870b44ad --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b60d3c5048302906962231.md @@ -0,0 +1,176 @@ +--- +id: 63b60d3c5048302906962231 +title: Step 14 +challengeType: 0 +dashedName: step-14 +--- + +# --description-- + +It is time to start writing the script that makes your form work. Begin by getting the `form` element (using the `id`) and storing it in a variable called `calorieCounter`. + +# --hints-- + +You should create a variable called `calorieCounter`. + +```js +assert.isDefined(calorieCounter); +``` + +You should use `document.getElementById()` to get the `#calorie-counter` element. + +```js +assert.match(code, /document\.getElementById\(\s*('|")calorie-counter\1\s*\)/g); +``` + +You should store the `#calorie-counter` element in a variable called `calorieCounter`. + +```js +assert.equal(calorieCounter, document.getElementById('calorie-counter')); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b613f367584d2a5d041b7d.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b613f367584d2a5d041b7d.md new file mode 100644 index 00000000000..44e1c274573 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b613f367584d2a5d041b7d.md @@ -0,0 +1,195 @@ +--- +id: 63b613f367584d2a5d041b7d +title: Step 15 +challengeType: 0 +dashedName: step-15 +--- + +# --description-- + +Get your `#budget` element and assign it to `budgetNumberInput`, and your `#entry-dropdown` element and assign it to `entryDropdown`. + +# --hints-- + +You should declare a variable called `budgetNumberInput`. + +```js +assert.isDefined(budgetNumberInput); +``` + +You should use `document.getElementById()` to get the `#budget` element. + +```js +assert.match(code, /document\.getElementById\(\s*('|")budget\1\s*\)/g); +``` + +You should store the `#budget` element in a variable called `budgetNumberInput`. + +```js +assert.equal(budgetNumberInput, document.getElementById('budget')); +``` + +You should declare a variable called `entryDropdown`. + +```js +assert.isDefined(entryDropdown); +``` + +You should use `document.getElementById()` to get the `#entry-dropdown` element. + +```js +assert.match(code, /document\.getElementById\(\s*('|")entry-dropdown\1\s*\)/g); +``` + +You should store the `#entry-dropdown` element in a variable called `entryDropdown`. + +```js +assert.equal(entryDropdown, document.getElementById('entry-dropdown')); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +--fcc-editable-region-- +const calorieCounter = document.getElementById('calorie-counter'); + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b61490e633a22b4593e62f.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b61490e633a22b4593e62f.md new file mode 100644 index 00000000000..6cbbeb5ab4a --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b61490e633a22b4593e62f.md @@ -0,0 +1,215 @@ +--- +id: 63b61490e633a22b4593e62f +title: Step 16 +challengeType: 0 +dashedName: step-16 +--- + +# --description-- + +Following the same pattern, assign your `#add-entry` element to `addEntryButton`, your `#clear` element to `clearButton`, and your `#output` element to `output`. + +# --hints-- + +You should declare a variable called `addEntryButton`. + +```js +assert.isDefined(addEntryButton); +``` + +You should use `document.getElementById()` to get the `#add-entry` element. + +```js +assert.match(code, /document\.getElementById\(\s*('|")add-entry\1\s*\)/g); +``` + +You should assign the `#add-entry` element to `addEntryButton`. + +```js +assert.equal(addEntryButton, document.getElementById('add-entry')); +``` + +You should declare a variable called `clearButton`. + +```js +assert.isDefined(clearButton); +``` + +You should use `document.getElementById()` to get the `#clear` element. + +```js +assert.match(code, /document\.getElementById\(\s*('|")clear\1\s*\)/g); +``` + +You should assign the `#clear` element to `clearButton`. + +```js +assert.equal(clearButton, document.getElementById('clear')); +``` + +You should declare a variable called `output`. + +```js +assert.isDefined(output); +``` + +You should use `document.getElementById()` to get the `#output` element. + +```js +assert.match(code, /document\.getElementById\(\s*('|")output\1\s*\)/g); +``` + +You should assign the `#output` element to `output`. + +```js +assert.equal(output, document.getElementById("output")); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +--fcc-editable-region-- +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b614e6a1f7fe2cef6312dc.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b614e6a1f7fe2cef6312dc.md new file mode 100644 index 00000000000..99c1985862c --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b614e6a1f7fe2cef6312dc.md @@ -0,0 +1,182 @@ +--- +id: 63b614e6a1f7fe2cef6312dc +title: Step 17 +challengeType: 0 +dashedName: step-17 +--- + +# --description-- + +Declare an `isError` variable and set it to `false`, but use `let` so you can reassign it later. + +# --hints-- + +You should declare an `isError` variable. + +```js +assert.isDefined(isError); +``` + +Your `isError` variable should be set to `false`. + +```js +assert.isFalse(isError); +``` + +You should use `let` to declare your `isError` variable. + +```js +assert.match(code, /let\s+isError\s*=\s*false/g); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +--fcc-editable-region-- +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b6152e6aff882db819fc1e.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b6152e6aff882db819fc1e.md new file mode 100644 index 00000000000..436b65b80d6 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b6152e6aff882db819fc1e.md @@ -0,0 +1,192 @@ +--- +id: 63b6152e6aff882db819fc1e +title: Step 18 +challengeType: 0 +dashedName: step-18 +--- + +# --description-- + +Even though you set an `input` element to be a number, JavaScript receives a string value. You need to write a function to clean the string value and ensure you have a number. + +Start by declaring a `cleanInputString` function that takes a `str` argument. + +# --hints-- + +You should declare a `cleanInputString` variable. + +```js +assert.isDefined(cleanInputString); +``` + +Your `cleanInputString` variable should be a function. + +```js +assert.isFunction(cleanInputString); +``` + +Your `cleanInputString` function should take a `str` argument. + +```js +assert.match(cleanInputString?.toString(), /\(str\)/); +``` + +`cleanInputString` should be an empty function. + +```js +assert.match(cleanInputString?.toString(), /\{\s*\}/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b61584def8fa2ebcc259e0.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b61584def8fa2ebcc259e0.md new file mode 100644 index 00000000000..f80fb3fdf2e --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63b61584def8fa2ebcc259e0.md @@ -0,0 +1,182 @@ +--- +id: 63b61584def8fa2ebcc259e0 +title: Step 19 +challengeType: 0 +dashedName: step-19 +--- + +# --description-- + +You need to split your `str` into individual characters. Remember that strings have a `.split()` method, and if you pass an empty string it will split on every character. + +Declare a `strArray` variable and assign it that split value. + +# --hints-- + +Your `cleanInputString` function should declare a `strArray` variable. + +```js +assert.match(cleanInputString.toString(), /strArray\s*=/); +``` + +Your `strArray` variable should be assigned the value of `str.split('')`. + +```js +assert.match(cleanInputString.toString(), /strArray\s*=\s*str\.split\(\s*('|")\1\s*\)/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf43be3f969d24d4ed233c.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf43be3f969d24d4ed233c.md new file mode 100644 index 00000000000..6f74ea42501 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf43be3f969d24d4ed233c.md @@ -0,0 +1,181 @@ +--- +id: 63bf43be3f969d24d4ed233c +title: Step 20 +challengeType: 0 +dashedName: step-20 +--- + +# --description-- + +Declare a `cleanStrArray` variable and assign it an empty array. You will use this to store your valid number characters. + +# --hints-- + +Your `cleanInputString` should declare a variable called `cleanStrArray`. + +```js +assert.match(cleanInputString.toString(), /cleanStrArray\s*/g); +``` + +Your `cleanStrArray` variable should be assigned an empty array. + +```js +assert.match(cleanInputString.toString(), /cleanStrArray\s*=\s*\[\s*\]/g); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + const strArray = str.split(''); + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf446945d34d25e6db6e4f.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf446945d34d25e6db6e4f.md new file mode 100644 index 00000000000..8bf06ccc530 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf446945d34d25e6db6e4f.md @@ -0,0 +1,195 @@ +--- +id: 63bf446945d34d25e6db6e4f +title: Step 21 +challengeType: 0 +dashedName: step-21 +--- + +# --description-- + +Use a `for` loop to iterate through each character in your `strArray` array. + +# --hints-- + +Your `cleanInputString` function should have a `for` loop. + +```js +assert.match(cleanInputString.toString(), /for\s*\(/g); +``` + +Your `for` loop should initialize a variable called `i` to `0`. + +```js +assert.match(cleanInputString.toString(), /for\s*\(\s*(let|var)\s+i\s*=\s*0\s*;/g); +``` + +Your `for` loop should have a condition that checks if `i` is less than the length of `strArray`. + +```js +assert.match(cleanInputString.toString(), /for\s*\(\s*(let|var)\s+i\s*=\s*0\s*;\s*i\s*<\s*strArray\.length\s*;/g); +``` + +Your `for` loop should increment `i` by `1` each time it runs. Use the increment operator for this. + +```js +assert.match(cleanInputString.toString(), /for\s*\(\s*(let|var)\s+i\s*=\s*0\s*;\s*i\s*<\s*strArray\.length\s*;\s*i\s*\+\+\s*\)/g); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + const strArray = str.split(''); + const cleanStrArray = []; + + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf45ce0dc8d4270760c6d0.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf45ce0dc8d4270760c6d0.md new file mode 100644 index 00000000000..a432c6687d5 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf45ce0dc8d4270760c6d0.md @@ -0,0 +1,200 @@ +--- +id: 63bf45ce0dc8d4270760c6d0 +title: Step 22 +challengeType: 0 +dashedName: step-22 +--- + +# --description-- + +Within your loop, you need to check if the character in `strArray` at index `i` is not `+`, `-`, or a space. If it is not, `push` it to the `cleanStrArray`. + +To check your character, see if the array `["+", "-", " "]` includes the character – you can use the `.includes()` method on the array to do this. + +# --hints-- + +Your `for` loop should have an `if` statement. + +```js +assert.match(cleanInputString.toString(), /for\s*\(\s*(let|var)\s+i\s*=\s*0\s*;\s*i\s*<\s*strArray\.length\s*;\s*i\s*\+\+\s*\)\s*\{\s*if\s*\(/); +``` + +Your `for` loop should use `!["+", "-", " "].includes()`. + +```js +// the loop protection injects code so we have to look at the raw code directly +assert.match(code, /for\s*\(\s*(let|var)\s+i\s*=\s*0\s*;\s*i\s*<\s*strArray\.length\s*;\s*i\s*\+\+\s*\)\s*\{\s*if\s*\(!\[("|')\+\2\s*,\s*("|')-\3\s*,\s*("|')\s\4\s*\]\.includes\(/); +``` + +Your `for` loop should see if `strArray[i]` is found in `["+", "-", " "]`. + +```js +assert.match(code, /for\s*\(\s*(let|var)\s+i\s*=\s*0\s*;\s*i\s*<\s*strArray\.length\s*;\s*i\s*\+\+\s*\)\s*\{\s*if\s*\(!\[("|')\+\2\s*,\s*("|')-\3\s*,\s*("|')\s\4\s*\]\.includes\(\s*strArray\[i\]\s*\)\)\s*\{/); +``` + +Your `for` loop should `push` `strArray[i]` to `cleanStrArray`. + +```js +assert.match(code, /for\s*\(\s*(let|var)\s+i\s*=\s*0\s*;\s*i\s*<\s*strArray\.length\s*;\s*i\s*\+\+\s*\)\s*\{\s*if\s*\(!\[("|')\+\2\s*,\s*("|')-\3\s*,\s*("|')\s\4\s*\]\.includes\(\s*strArray\[i\]\s*\)\)\s*\{\s*cleanStrArray\.push\(\s*strArray\[i\]\s*\)\s*\}/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + const strArray = str.split(''); + const cleanStrArray = []; + + for (let i = 0; i < strArray.length; i++) { + + } +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf461011fca327d3b60fa8.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf461011fca327d3b60fa8.md new file mode 100644 index 00000000000..f74ff636c5b --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf461011fca327d3b60fa8.md @@ -0,0 +1,213 @@ +--- +id: 63bf461011fca327d3b60fa8 +title: Step 23 +challengeType: 0 +dashedName: step-23 +--- + +# --description-- + +While looping through the string works, creating a new array is inefficient for memory and runtime performance. Instead, you can use Regular Expressions (referred to as "regex") to match specific characters. + +Regex in JavaScript is indicated by a pattern wrapped in forward slashes – for example: + +```js +const regex = /hello/; +``` + +Remove your existing code within the `cleanInputString` function. Declare a `regex` variable and assign it the value from the example above. + +# --hints-- + +You should remove the `cleanStrArray` variable. + +```js +assert.notMatch(cleanInputString.toString(), /cleanStrArray/); +``` + +You should remove the `strArray` variable. + +```js +assert.notMatch(cleanInputString.toString(), /strArray/); +``` + +You should not have a `for` loop. + +```js +assert.notMatch(cleanInputString.toString(), /for/); +``` + +You should declare a `regex` variable. + +```js +assert.match(cleanInputString.toString(), /regex\s*=/); +``` + +Your `regex` variable should be set to the regular expression `/hello/`. + +```js +assert.match(cleanInputString.toString(), /regex\s*=\s*\/hello\//); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + const strArray = str.split(''); + const cleanStrArray = []; + + for (let i = 0; i < strArray.length; i++) { + if (!["+", "-", " "].includes(strArray[i])) { + cleanStrArray.push(strArray[i]) + } + } +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf47fd40599f29827f484d.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf47fd40599f29827f484d.md new file mode 100644 index 00000000000..0f781eb61cf --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf47fd40599f29827f484d.md @@ -0,0 +1,176 @@ +--- +id: 63bf47fd40599f29827f484d +title: Step 24 +challengeType: 0 +dashedName: step-24 +--- + +# --description-- + +The pattern you currently have will match the exact text `hello`, which is not what you want to match. You want to look for `+`, `-`, or spaces. Replace the pattern in your `regex` variable with `\+-` to look for plus and minus characters. + +Note that you need to use the `\` to escape the `+`, because a `+` has a special meaning in regular expressions. + +# --hints-- + +Your `regex` variable should be set to the regular expression `/\+-/`. + +```js +assert.match(cleanInputString.toString(), /regex\s*=\s*\/\\\+-\//); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + const regex = /hello/; +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf492b6dfb292a79f0e675.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf492b6dfb292a79f0e675.md new file mode 100644 index 00000000000..25d6d2447fb --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf492b6dfb292a79f0e675.md @@ -0,0 +1,174 @@ +--- +id: 63bf492b6dfb292a79f0e675 +title: Step 25 +challengeType: 0 +dashedName: step-25 +--- + +# --description-- + +In regex, shorthand character classes allow you to match specific characters without having to write those characters in your pattern. Shorthand character classes are preceded with a backslash (`\`). The character class `\s` will match any whitespace character. Add this to your regex pattern. + +# --hints-- + +Your `regex` variable should be set to the regular expression `/\+-\s/`. + +```js +assert.match(cleanInputString.toString(), /regex\s*=\s*\/\\\+-\\s\//) +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + const regex = /\+-/; +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf4bfe9de3852be51c8f86.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf4bfe9de3852be51c8f86.md new file mode 100644 index 00000000000..3b18f0aac60 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf4bfe9de3852be51c8f86.md @@ -0,0 +1,188 @@ +--- +id: 63bf4bfe9de3852be51c8f86 +title: Step 26 +challengeType: 0 +dashedName: step-26 +--- + +# --description-- + +Your current pattern won't work just yet. `/+-\s/` looks for `+`, `-`, and a space *in order*. This would match `+- hello` but would not match `+hello`. + +To tell the pattern to match each of these characters individually, you need to turn them into a character class. This is done by wrapping the characters you want to match in brackets. For example, this pattern will match the characters `h`, `e`, `l`, or `o`: + +```js +const regex = /[helo]/; +``` + +Turn your `+-\s` pattern into a character class. Note that you no longer need to escape the `+` character, because you are using a character class. + +# --hints-- + +Your `regex` variable should be set to the regular expression `[+-\s]`. + +```js +assert.match(cleanInputString.toString(), /regex\s*=\s*\/\[\\?\+-\\s\]\//) +``` + +You should not escape the `+` character in your regular expression. + +```js +assert.match(cleanInputString.toString(), /regex\s*=\s*\/\[\+-\\s\]\//); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + const regex = /\+-\s/; +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf4d351e06432ce9bf3627.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf4d351e06432ce9bf3627.md new file mode 100644 index 00000000000..30baf30ed58 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf4d351e06432ce9bf3627.md @@ -0,0 +1,180 @@ +--- +id: 63bf4d351e06432ce9bf3627 +title: Step 27 +challengeType: 0 +dashedName: step-27 +--- + +# --description-- + +Regex can also take specific flags to alter the pattern matching behavior. Flags are added after the closing `/`. The `g` flag, which stands for "global", will tell the pattern to continue looking after it has found a match. Here is an example: + +```js +const helloRegex = /hello/g; +``` + +Add the `g` flag to your regex pattern. + +# --hints-- + +You should add the `g` flag to your `regex` value. + +```js +assert.match(cleanInputString.toString(), /regex\s*=\s*\/\[\+-\\s\]\/g/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + const regex = /[+-\s]/; +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf511b85b6082e54dc1573.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf511b85b6082e54dc1573.md new file mode 100644 index 00000000000..4b35b49f7b9 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf511b85b6082e54dc1573.md @@ -0,0 +1,199 @@ +--- +id: 63bf511b85b6082e54dc1573 +title: Step 28 +challengeType: 0 +dashedName: step-28 +--- + +# --description-- + +Strings have a `.replace()` method which allows you to replace characters in the string with another string. `.replace` takes two arguments. The first is the character sequence to replace – this can either be a string or a regex pattern. The second is the string to replace that sequence with. For example, this would replace all instances of `l` with `1`: + +```js +"hello".replace(/l/g, "1"); +``` + +Use your `regex` to replace all instances of `+`, `-`, and a space in `str` with an empty string. Return this value. + +# --hints-- + +Your `cleanInputString` should call the `replace` method of `str`. + +```js +assert.match(cleanInputString.toString(), /str\.replace\(/); +``` + +You should pass `regex` as the first argument to `replace`. + +```js +assert.match(cleanInputString.toString(), /str\.replace\(\s*regex\s*/); +``` + +You should pass `""` as the second argument to `replace`. + +```js +assert.match(cleanInputString.toString(), /str\.replace\(\s*regex\s*,\s*("|')\1\s*\)/); +``` + +Your `cleanInputString` function should directly return the result of your `replace` method. + +```js +assert.match(cleanInputString.toString(), /return\s*str\.replace\(\s*regex\s*,\s*("|')\1\s*\)/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +--fcc-editable-region-- +function cleanInputString(str) { + const regex = /[+-\s]/g; + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5230bccd1c2f5c13e1ce.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5230bccd1c2f5c13e1ce.md new file mode 100644 index 00000000000..b6eef00a30b --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5230bccd1c2f5c13e1ce.md @@ -0,0 +1,191 @@ +--- +id: 63bf5230bccd1c2f5c13e1ce +title: Step 29 +challengeType: 0 +dashedName: step-29 +--- + +# --description-- + +In HTML, number inputs allow for exponential notation (such as `1e10`). You need to filter those out. + +Start by creating a function called `isInvalidInput` – it should take a single `str` parameter. + +# --hints-- + +You should declare an `isInvalidInput` variable. + +```js +assert.isDefined(isInvalidInput) +``` + +`isInvalidInput` should be a function. + +```js +assert.isFunction(isInvalidInput) +``` + +`isInvalidInput` should take a single `str` parameter. + +```js +assert.match(isInvalidInput?.toString(), /\(\s*str\s*\)/) +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf598a4c807930a13a1a27.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf598a4c807930a13a1a27.md new file mode 100644 index 00000000000..778a809571e --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf598a4c807930a13a1a27.md @@ -0,0 +1,185 @@ +--- +id: 63bf598a4c807930a13a1a27 +title: Step 30 +challengeType: 0 +dashedName: step-30 +--- + +# --description-- + +Declare a `regex` variable, and assign it a regex that matches the character `e`. + +# --hints-- + +Your `isInvalidInput` function should have a `regex` variable. + +```js +assert.match(isInvalidInput.toString(), /regex\s*=/); +``` + +Your `regex` variable should be set to `/e/`. + +```js +assert.match(isInvalidInput.toString(), /regex\s*=\s*\/e\//); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +--fcc-editable-region-- +function isInvalidInput(str) { + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5a518d54f63181ab639a.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5a518d54f63181ab639a.md new file mode 100644 index 00000000000..2bf1aa0f9a3 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5a518d54f63181ab639a.md @@ -0,0 +1,179 @@ +--- +id: 63bf5a518d54f63181ab639a +title: Step 31 +challengeType: 0 +dashedName: step-31 +--- + +# --description-- + +The `e` in a number input can also be an uppercase `E`. Regex has a flag for this, however – the `i` flag, which stands for "insensitive". This flag makes your pattern case-insensitive. Add the `i` flag to your regex pattern. + +# --hints-- + +Your `regex` value should have the `i` flag. + +```js +assert.match(isInvalidInput.toString(), /regex\s*=\s*\/e\/i/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +--fcc-editable-region-- +function isInvalidInput(str) { + const regex = /e/; +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5a92fd148d3264d5322b.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5a92fd148d3264d5322b.md new file mode 100644 index 00000000000..19873a84492 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5a92fd148d3264d5322b.md @@ -0,0 +1,187 @@ +--- +id: 63bf5a92fd148d3264d5322b +title: Step 32 +challengeType: 0 +dashedName: step-32 +--- + +# --description-- + +Number inputs only allow the `e` to occur between two digits. To match any number, you can use the character class `[0-9]`. This will match any digit between `0` and `9`. + +Add this character class before and after `e` in your pattern. + +# --hints-- + +You should add the `[0-9]` character class before `e` in your regular expression. + +```js +assert.match(isInvalidInput.toString(), /regex\s*=\s*\/\[0-9\]e/); +``` + +You should add the `[0-9]` character class after `e` in your regular expression. + +```js +assert.match(isInvalidInput.toString(), /regex\s*=\s*\/\[0-9\]e\[0-9\]\//); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +--fcc-editable-region-- +function isInvalidInput(str) { + const regex = /e/i; +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5adfe2981b332eb007b6.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5adfe2981b332eb007b6.md new file mode 100644 index 00000000000..75477ddd763 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5adfe2981b332eb007b6.md @@ -0,0 +1,185 @@ +--- +id: 63bf5adfe2981b332eb007b6 +title: Step 33 +challengeType: 0 +dashedName: step-33 +--- + +# --description-- + +The `+` modifier in a regex allows you to match a pattern that occurs one or more times. To match your digit pattern one or more times, add a plus after each of the digit character classes. For example: `[0-9]+`. + +# --hints-- + +You should add the `+` modifier to the character class before `e` in your regular expression. + +```js +assert.match(isInvalidInput.toString(), /regex\s*=\s*\/\[0-9\]\+e/); +``` + +You should add the `+` modifier to the character class after `e` in your regular expression. + +```js +assert.match(isInvalidInput.toString(), /regex\s*=\s*\/\[0-9\]\+e\[0-9\]\+\//); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +--fcc-editable-region-- +function isInvalidInput(str) { + const regex = /[0-9]e[0-9]/i; +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5bcfebff0734593fad19.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5bcfebff0734593fad19.md new file mode 100644 index 00000000000..95686b3c3a0 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5bcfebff0734593fad19.md @@ -0,0 +1,185 @@ +--- +id: 63bf5bcfebff0734593fad19 +title: Step 34 +challengeType: 0 +dashedName: step-34 +--- + +# --description-- + +There is a shorthand character class to match any digit: `\d`. Replace your `[0-9]` character classes with this shorthand. + +# --hints-- + +You should replace the `[0-9]` character class before `e` with `\d` in your regular expression. + +```js +assert.match(isInvalidInput.toString(), /regex\s*=\s*\/\\d\+e/); +``` + +You should replace the `[0-9]` character class after `e` with `\d` in your regular expression. + +```js +assert.match(isInvalidInput.toString(), /regex\s*=\s*\/\\d\+e\\d\+\//); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +--fcc-editable-region-- +function isInvalidInput(str) { + const regex = /[0-9]+e[0-9]+/i; +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5c438f523a359769106c.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5c438f523a359769106c.md new file mode 100644 index 00000000000..f6f61282ce9 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5c438f523a359769106c.md @@ -0,0 +1,194 @@ +--- +id: 63bf5c438f523a359769106c +title: Step 35 +challengeType: 0 +dashedName: step-35 +--- + +# --description-- + +Strings have a `.match()` method, which takes a regex argument. `.match()` will return an array of match results – containing either the first match, or all matches if the global flag is used. + +Return the result of calling the `.match()` method on `str` and passing your `regex` variable as the argument. You'll use this match result later on. + +# --hints-- + +Your `isInvalidInput` function should call the `.match()` method on `str`. + +```js +assert.match(isInvalidInput.toString(), /str\.match\(/); +``` + +You should pass `regex` as the argument to the `.match()` method. + +```js +assert.match(isInvalidInput.toString(), /str\.match\(\s*regex\s*\)/); +``` + +Your `isInvalidInput` function should directly return the result of the `.match()` call. + +```js +assert.match(isInvalidInput.toString(), /return\s+str\.match\(\s*regex\s*\)/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +--fcc-editable-region-- +function isInvalidInput(str) { + const regex = /\d+e\d+/i; + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5cf03b50bf36cfbe94ea.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5cf03b50bf36cfbe94ea.md new file mode 100644 index 00000000000..9a3f0df7bef --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf5cf03b50bf36cfbe94ea.md @@ -0,0 +1,194 @@ +--- +id: 63bf5cf03b50bf36cfbe94ea +title: Step 36 +challengeType: 0 +dashedName: step-36 +--- + +# --description-- + +Your next step is to allow users to add entries to the calorie counter. Declare an empty function `addEntry`. This function should not take any parameters. + +# --hints-- + +You should declare an `addEntry` variable. + +```js +assert.isDefined(addEntry); +``` + +Your `addEntry` variable should be a function. + +```js +assert.isFunction(addEntry); +``` + +Your `addEntry` function should not take any parameters. + +```js +assert.match(addEntry?.toString(), /\(\s*\)/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +function isInvalidInput(str) { + const regex = /\d+e\d+/i; + return str.match(regex); +} + +--fcc-editable-region-- + +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1dfbd56c71e278800010c.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1dfbd56c71e278800010c.md new file mode 100644 index 00000000000..1bc417c8bbb --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1dfbd56c71e278800010c.md @@ -0,0 +1,198 @@ +--- +id: 63c1dfbd56c71e278800010c +title: Step 37 +challengeType: 0 +dashedName: step-37 +--- + +# --description-- + +You'll need to know which category the entry goes in. Thankfully, you added a dropdown for the user to select a category. + +Remember that you queried that dropdown earlier in your JavaScript and assigned it to the `entryDropdown` button. Use concatenation to add `#` to the beginning of the `value` property of `entryDropdown`, and assign that result to a `targetId` variable. + +# --hints-- + +Your `addEntry` function should have a `targetId` variable. + +```js +assert.match(addEntry.toString(), /targetId\s*=/); +``` + +Your `targetId` variable should start with the string `#`. + +```js +assert.match(addEntry.toString(), /targetId\s*=\s*('|")#\1/); +``` + +You should use concatenation to add `entryDropdown.value` after your `#` string. + +```js +assert.match(addEntry.toString(), /targetId\s*=\s*('|")#\1\s*\+\s*entryDropdown\.value/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +function isInvalidInput(str) { + const regex = /\d+e\d+/i; + return str.match(regex); +} + +--fcc-editable-region-- +function addEntry() { + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e0af28078f2dfad9eb3e.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e0af28078f2dfad9eb3e.md new file mode 100644 index 00000000000..413b5f76d84 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e0af28078f2dfad9eb3e.md @@ -0,0 +1,203 @@ +--- +id: 63c1e0af28078f2dfad9eb3e +title: Step 38 +challengeType: 0 +dashedName: step-38 +--- + +# --description-- + +Now you need to target the `.input-container` element within the element that has your `targetId`. Declare a new `targetInputContainer` variable, and assign it the value of `document.querySelector()`. Use concatenation to separate `targetId` and `'.input-container'` with a space, and pass that string to `querySelector()`. + +# --hints-- + +Your `addEntry` function should have a `targetInputContainer` variable. + +```js +assert.match(addEntry.toString(), /targetInputContainer\s*=/); +``` + +Your `targetInputContainer` variable should be set to `document.querySelector()`. + +```js +assert.match(addEntry.toString(), /targetInputContainer\s*=\s*document\.querySelector\(/); +``` + +You should pass `targetId` to your `querySelector()` method. + +```js +assert.match(addEntry.toString(), /targetInputContainer\s*=\s*document\.querySelector\(\s*targetId\s*/); +``` + +You should concatenate `' .input-container'` to `targetId`. Remember to include the space at the beginning of `.input-container`. + +```js +assert.match(addEntry.toString(), /targetInputContainer\s*=\s*document\.querySelector\(\s*targetId\s*\s*\+\s*('|")\s\.input-container\1\s*\)/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +function isInvalidInput(str) { + const regex = /\d+e\d+/i; + return str.match(regex); +} + +--fcc-editable-region-- +function addEntry() { + const targetId = '#' + entryDropdown.value; + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e1965a898d302e0af4e3.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e1965a898d302e0af4e3.md new file mode 100644 index 00000000000..914ba9a0f67 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e1965a898d302e0af4e3.md @@ -0,0 +1,203 @@ +--- +id: 63c1e1965a898d302e0af4e3 +title: Step 39 +challengeType: 0 +dashedName: step-39 +--- + +# --description-- + +JavaScript has a feature called template literals, which allow you to interpolate variables directly within a string. Template literals are denoted with backticks ``` `` ```, as opposed to single or double quotes. Variables can be passed in to a template literal by surrounding the variable with `${}` – the value of the variable will be inserted into the string. + +For example: + +```js +const name = "Naomi"; +const templateLiteral = `Hello, my name is ${name}~!`; +console.log(templateLiteral); +``` + +The console will show the string "Hello, my name is Naomi~!". + +Replace your concatenated string in the `querySelector` with a template literal – be sure to keep the space between your `targetId` variable and `.input-container`. + +# --hints-- + +You should use a template literal in your `querySelector` method. + +```js +assert.match(code, /const\s+targetInputContainer\s*=\s*document\.querySelector\(`.*`\)/); +``` + +Your template literal should have the value `{targetId} .input-container`. + +```js +assert.match(code, /const\s+targetInputContainer\s*=\s*document\.querySelector\(`\$\{targetId\}\s\.input-container`\s*\)/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +function isInvalidInput(str) { + const regex = /\d+e\d+/i; + return str.match(regex); +} + +--fcc-editable-region-- +function addEntry() { + const targetId = '#' + entryDropdown.value; + const targetInputContainer = document.querySelector(targetId + ' .input-container'); +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e5b4b3c8a031def3bd65.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e5b4b3c8a031def3bd65.md new file mode 100644 index 00000000000..6aeab26c100 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e5b4b3c8a031def3bd65.md @@ -0,0 +1,197 @@ +--- +id: 63c1e5b4b3c8a031def3bd65 +title: Step 40 +challengeType: 0 +dashedName: step-40 +--- + +# --description-- + +Thanks to template literals, you actually don't need the `targetId` variable at all. Remove that variable, and update your template literal to replace `targetId` with `entryDropdown.value` – remember to add `#` before that, in the string. + +# --hints-- + +You should remove the `targetId` variable. + +```js +assert.notMatch(addEntry.toString(), /targetId\s*=/); +``` + +You should replace the `targetId` reference in your template literal with `entryDropdown.value`. + +```js +assert.match(code, /const\s+targetInputContainer\s*=\s*document\.querySelector\(`#?\$\{entryDropdown\.value\}\s\.input-container`\s*\)/); +``` + +You should add `#` at the beginning of your template literal. + +```js +assert.match(code, /const\s+targetInputContainer\s*=\s*document\.querySelector\(`#\$\{entryDropdown\.value\}\s\.input-container`\s*\)/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +function isInvalidInput(str) { + const regex = /\d+e\d+/i; + return str.match(regex); +} + +--fcc-editable-region-- +function addEntry() { + const targetId = '#' + entryDropdown.value; + const targetInputContainer = document.querySelector(`${targetId} .input-container`); +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e704ee12703347625900.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e704ee12703347625900.md new file mode 100644 index 00000000000..b658496aeee --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c1e704ee12703347625900.md @@ -0,0 +1,197 @@ +--- +id: 63c1e704ee12703347625900 +title: Step 41 +challengeType: 0 +dashedName: step-41 +--- + +# --description-- + +You will want to number the entries a user adds. Declare an `entryNumber` variable and give it the value of `targetInputContainer.querySelectorAll()`. You do not need to pass an argument to the query selector yet. + +# --hints-- + +You should have an `entryNumber` variable. + +```js +assert.match(addEntry.toString(), /entryNumber\s*=/); +``` + +Your `entryNumber` variable should have the value of `targetInputContainer.querySelectorAll()`. + +```js +assert.match(addEntry.toString(), /entryNumber\s*=\s*targetInputContainer\.querySelectorAll\(/); +``` + +You should not pass an argument to `querySelectorAll()`. + +```js +assert.match(addEntry.toString(), /entryNumber\s*=\s*targetInputContainer\.querySelectorAll\(\s*\)/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +function isInvalidInput(str) { + const regex = /\d+e\d+/i; + return str.match(regex); +} + +--fcc-editable-region-- +function addEntry() { + const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`); + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c2164c0df38a382062c4af.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c2164c0df38a382062c4af.md new file mode 100644 index 00000000000..15622f17e14 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c2164c0df38a382062c4af.md @@ -0,0 +1,201 @@ +--- +id: 63c2164c0df38a382062c4af +title: Step 42 +challengeType: 0 +dashedName: step-42 +--- + +# --description-- + +Each entry will have a text input for the entry's name, and a number input for the calories. To get a count of the number of entries, you can query by text inputs. Note that you cannot query by number inputs, as you have an extra number input for the user's calorie budget. + +Pass the string `input[type="text"]` to the `querySelectorAll()` method. Remember that you will need to use single quotes for your string, so that you can use double quotes within. + +This will return a `NodeList` of all the text inputs in the form. You can then access the `length` property of the `NodeList` to get the number of entries. Do this on the same line. + +# --hints-- + +You should pass the string `input[type="text"]` to the `querySelectorAll()` method. + +```js +assert.match(addEntry.toString(), /entryNumber\s*=\s*targetInputContainer\.querySelectorAll\(\s*'input\[type="text"]'\)/) +``` + +You should access the `length` property of your `querySelectorAll()`. + +```js +assert.match(addEntry.toString(), /\.querySelectorAll\(\s*'input\[type="text"]'\)\.length/) +``` + +Your `entryNumber` variable should be the `length` of the `querySelectorAll`. + +```js +assert.match(addEntry.toString(), /entryNumber\s*=\s*targetInputContainer\.querySelectorAll\(\s*'input\[type="text"]'\)\.length/) +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +function isInvalidInput(str) { + const regex = /\d+e\d+/i; + return str.match(regex); +} + +--fcc-editable-region-- +function addEntry() { + const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`); + const entryNumber = targetInputContainer.querySelectorAll(); +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c216da562fbb3957b9cb2c.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c216da562fbb3957b9cb2c.md new file mode 100644 index 00000000000..ae9177aa122 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c216da562fbb3957b9cb2c.md @@ -0,0 +1,192 @@ +--- +id: 63c216da562fbb3957b9cb2c +title: Step 43 +challengeType: 0 +dashedName: step-43 +--- + +# --description-- + +Now you need to build your dynamic HTML string to add to the webpage. Declare a new `HTMLString` variable, and assign it an empty template literal string. + +# --hints-- + +Your `addEntry` function should have an `HTMLString` variable. + +```js +assert.match(addEntry.toString(), /HTMLString\s*=/) +``` + +Your `HTMLString` should be an empty template literal. + +```js +assert.match(code, /HTMLString\s*=\s*``/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + Calorie Counter + + +
+

Calorie Counter

+
+
+ + +
+ Breakfast +
+
+
+ Lunch +
+
+
+ Dinner +
+
+
+ Snacks +
+
+
+ Exercise +
+
+
+ + + + + +
+
+ + +
+
+
+
+
+ + + +``` + +```css +body { + font-family: "Lato", Arial; +} + +h1 { + text-align: center; +} + +.container { + width: 90%; + max-width: 680px; +} + +h1, +.container, +.output { + margin: 20px auto; +} + +label, +legend { + font-weight: bold; +} + +.input-container { + display: flex; + flex-direction: column; +} + +button:hover { + cursor: pointer; +} + +fieldset, +label, +button, +input, +select { + margin-bottom: 10px; +} + +.output { + border: 2px solid black; + padding: 10px; + text-align: center; +} + +.hide { + display: none; +} + +.output span { + font-weight: bold; + font-size: 1.2em; +} + +.surplus { + color: #006627; +} + +.deficit { + color: #B30000; +} +``` + +```js +const calorieCounter = document.getElementById('calorie-counter'); +const budgetNumberInput = document.getElementById('budget'); +const entryDropdown = document.getElementById('entry-dropdown'); +const addEntryButton = document.getElementById('add-entry'); +const clearButton = document.getElementById('clear'); +const output = document.getElementById('output'); +let isError = false; + +function cleanInputString(str) { + const regex = /[+-\s]/g; + return str.replace(regex, ''); +} + +function isInvalidInput(str) { + const regex = /\d+e\d+/i; + return str.match(regex); +} + +--fcc-editable-region-- +function addEntry() { + const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`); + const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length; + +} +--fcc-editable-region-- +``` diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c2171c1e5b6e3aa51768d0.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c2171c1e5b6e3aa51768d0.md new file mode 100644 index 00000000000..e8ced7f3436 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c2171c1e5b6e3aa51768d0.md @@ -0,0 +1,198 @@ +--- +id: 63c2171c1e5b6e3aa51768d0 +title: Step 44 +challengeType: 0 +dashedName: step-44 +--- + +# --description-- + +Start your `HTMLString` with a new line, then create a `label` element. Give that element the text `Entry # Name`, using your template literal syntax to replace `#` with the value of `entryNumber`. + +# --hints-- + +Your `HTMLString` variable should start with a new line. + +```js +assert.match(code, /HTMLString\s*=\s*`\n/); +``` + +You should add a `label` element on the new line. + +```js +assert.match(code, /HTMLString\s*=\s*`\n\s*