From 630e5e8b9051df125a94a2dcd40f670df360dc64 Mon Sep 17 00:00:00 2001 From: a2937 Date: Tue, 9 Jan 2024 22:27:49 -0500 Subject: [PATCH] fix(curriculum): improve regex in rpg project step 123 (#53052) Co-authored-by: Mama Naomi --- .../62a8e4dc6a60f85bf256a0cb.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8e4dc6a60f85bf256a0cb.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8e4dc6a60f85bf256a0cb.md index e2be1ba5576..5f4173f2439 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8e4dc6a60f85bf256a0cb.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-javascript-by-building-a-role-playing-game/62a8e4dc6a60f85bf256a0cb.md @@ -7,11 +7,11 @@ dashedName: step-123 # --description-- -JavaScript offers the built-in `Math` utility which offers a number of mathematical tools. One of those is `Math.random()`, which generates a random number between 0 and 1. Another is `Math.floor()`, which rounds a given number down to the nearest integer. +The `Math` object in JavaScript contains static properties and methods for mathematical constants and functions. One of those is `Math.random()`, which generates a random number from `0` (inclusive) to `1` (exclusive). Another is `Math.floor()`, which rounds a given number down to the nearest integer. Using these, you can generate a random number within a range. For example, this generates a random number between 1 and 5: `Math.floor(Math.random() * 5) + 1;`. -Following this pattern, use the addition operator (`+`) to add a random number between `1` and the value of `xp` to your `monsterHealth` variable change. +Following this pattern, use the addition operator (`+`) to add a random number between `1` and the value of `xp` to your `monsterHealth -= weapons[currentWeapon].power`. # --hints-- @@ -48,19 +48,19 @@ assert.match(attack.toString(), /Math\.random\(\)\s*\*\s*xp/); You should use `Math.floor()` to round the result of `Math.random() * xp` down. ```js -assert.match(attack.toString(), /Math\.floor\(\s*Math\.random\(\)\s*\*\s*xp\s*\)/); +assert.match(attack.toString(), /Math\.floor\(\s*Math\.random\(\)\s*\*\s*xp\s*.*\)/); ``` You should add `1` to the result of `Math.floor()`. ```js -assert.match(attack.toString(), /Math\.floor\(\s*Math\.random\(\)\s*\*\s*xp\s*\)\s*\+\s*1/); +assert.match(attack.toString(), /Math\.floor\(Math\.random\(\)\s*\*\s*xp(?:\s*\+\s*1)?\)(?:\s*\+ 1)?/); ``` You should add the result of `Math.floor(Math.random() * xp) + 1` to the result of `weapons[currentWeapon].power`. ```js -assert.match(attack.toString(), /monsterHealth\s*-=\s*weapons\[currentWeapon\]\.power\s*\+\s*Math\.floor\(\s*Math\.random\(\)\s*\*\s*xp\s*\)\s*\+\s*1/); +assert.match(attack.toString(), /monsterHealth\s*-=\s*weapons\[currentWeapon\]\.power\s*\+\s*Math\.floor\(Math\.random\(\)\s*\*\s*xp(?:\s*\+\s*1)?\)(?:\s*\+ 1)?/); ``` # --seed-- @@ -310,14 +310,15 @@ function goFight() { monsterHealthText.innerText = monsterHealth; } ---fcc-editable-region-- + function attack() { text.innerText = "The " + monsters[fighting].name + " attacks."; text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; health -= monsters[fighting].level; + --fcc-editable-region-- monsterHealth -= weapons[currentWeapon].power; + --fcc-editable-region-- } ---fcc-editable-region-- function dodge() {