From e3eccef3fb6adc52be3a0945ac044c77e79ad85e Mon Sep 17 00:00:00 2001 From: Ilenia <26656284+ilenia-magoni@users.noreply.github.com> Date: Thu, 2 Jan 2025 10:31:26 +0100 Subject: [PATCH] fix: use optional chaining to avoid errors (#57759) --- .../build-a-cash-register-project/build-a-cash-register.md | 4 ++-- .../build-a-palindrome-checker.md | 2 +- .../build-a-pokemon-search-app.md | 4 ++-- .../build-a-telephone-number-validator.md | 2 +- .../64475c0b61cddb6feaab4e2e.md | 2 +- .../lab-palindrome-checker/657bdc55a322aae1eac3838f.md | 2 +- .../64475c0b61cddb6feaab4e2e.md | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-cash-register-project/build-a-cash-register.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-cash-register-project/build-a-cash-register.md index 50bb031afbf..768d053e22e 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-cash-register-project/build-a-cash-register.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-cash-register-project/build-a-cash-register.md @@ -111,7 +111,7 @@ cashInput.dispatchEvent(new Event('change')); purchaseBtn.click(); assert.strictEqual( alertMessage - .trim() + ?.trim() .replace(/[.,?!]+$/g, '') .toLowerCase(), 'customer does not have enough money to purchase the item' @@ -148,7 +148,7 @@ cashInput.dispatchEvent(new Event('change')); purchaseBtn.click(); assert.strictEqual( alertMessage - .trim() + ?.trim() .replace(/[.,?!]+$/g, '') .toLowerCase(), 'customer does not have enough money to purchase the item' diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-palindrome-checker-project/build-a-palindrome-checker.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-palindrome-checker-project/build-a-palindrome-checker.md index 1058b263777..2a6003df583 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-palindrome-checker-project/build-a-palindrome-checker.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-palindrome-checker-project/build-a-palindrome-checker.md @@ -70,7 +70,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store inputEl.value = ''; inputEl.dispatchEvent(new Event('change')) checkBtn.click(); -assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please input a value'); +assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please input a value'); ``` When the `#text-input` element only contains the letter `A` and the `#check-btn` element is clicked, the `#result` element should contain the text `"A is a palindrome"`. diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-pokemon-search-app-project/build-a-pokemon-search-app.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-pokemon-search-app-project/build-a-pokemon-search-app.md index e14a4241f73..68879e3faf3 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-pokemon-search-app-project/build-a-pokemon-search-app.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-pokemon-search-app-project/build-a-pokemon-search-app.md @@ -153,7 +153,7 @@ async () => { if (!res.ok) { await new Promise(resolve => setTimeout(resolve, 1000)); // Additional delay to allow the alert to trigger - assert.include(['pokémon not found', 'pokemon not found'], alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase()); + assert.include(['pokémon not found', 'pokemon not found'], alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase()); } } catch (err) { throw new Error(err); @@ -375,7 +375,7 @@ async () => { if (!res.ok) { await new Promise(resolve => setTimeout(resolve, 2000)); // Additional delay to allow the alert to trigger - assert.include(['pokémon not found', 'pokemon not found'], alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase()); + assert.include(['pokémon not found', 'pokemon not found'], alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase()); } } catch (err) { throw new Error(err); diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-telephone-number-validator-project/build-a-telephone-number-validator.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-telephone-number-validator-project/build-a-telephone-number-validator.md index db9afb741db..e4d1b5a46fa 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-telephone-number-validator-project/build-a-telephone-number-validator.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-telephone-number-validator-project/build-a-telephone-number-validator.md @@ -103,7 +103,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store userInput.value = ''; checkBtn.click(); -assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a phone number'); +assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a phone number'); ``` When you click on the `#clear-btn` element, the content within the `#results-div` element should be removed. diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-recursion-by-building-a-decimal-to-binary-converter/64475c0b61cddb6feaab4e2e.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-recursion-by-building-a-decimal-to-binary-converter/64475c0b61cddb6feaab4e2e.md index 06b4be5a16d..0b98e7082bf 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-recursion-by-building-a-decimal-to-binary-converter/64475c0b61cddb6feaab4e2e.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-recursion-by-building-a-decimal-to-binary-converter/64475c0b61cddb6feaab4e2e.md @@ -31,7 +31,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store numberInput.value = ''; checkUserInput(); -assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number greater than or equal to 0'); +assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number greater than or equal to 0'); ``` # --seed-- diff --git a/curriculum/challenges/english/25-front-end-development/lab-palindrome-checker/657bdc55a322aae1eac3838f.md b/curriculum/challenges/english/25-front-end-development/lab-palindrome-checker/657bdc55a322aae1eac3838f.md index d903ae3e3c3..6cf21eceb8a 100644 --- a/curriculum/challenges/english/25-front-end-development/lab-palindrome-checker/657bdc55a322aae1eac3838f.md +++ b/curriculum/challenges/english/25-front-end-development/lab-palindrome-checker/657bdc55a322aae1eac3838f.md @@ -68,7 +68,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store inputEl.value = ''; inputEl.dispatchEvent(new Event('change')) checkBtn.click(); -assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please input a value'); +assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please input a value'); ``` When the `#text-input` element only contains the letter `A` and the `#check-btn` element is clicked, the `#result` element should contain the text `"A is a palindrome"`. diff --git a/curriculum/challenges/english/25-front-end-development/workshop-decimal-to-binary-converter/64475c0b61cddb6feaab4e2e.md b/curriculum/challenges/english/25-front-end-development/workshop-decimal-to-binary-converter/64475c0b61cddb6feaab4e2e.md index 06b4be5a16d..0b98e7082bf 100644 --- a/curriculum/challenges/english/25-front-end-development/workshop-decimal-to-binary-converter/64475c0b61cddb6feaab4e2e.md +++ b/curriculum/challenges/english/25-front-end-development/workshop-decimal-to-binary-converter/64475c0b61cddb6feaab4e2e.md @@ -31,7 +31,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store numberInput.value = ''; checkUserInput(); -assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number greater than or equal to 0'); +assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number greater than or equal to 0'); ``` # --seed--