Closed ghost closed 6 years ago
@devocija-it, thank you for submitting a fix for this longstanding issue! But unfortunately in my testing I found the regex to be just a bit too rigid. As it is now, I can only pass the challenge with the following code:
function testElseIf(val) {
if (val > 10) {
return "Greater than 10";
} else if (val < 5) {
return "Smaller than 5";
} else {
return "Between 5 and 10";
}
}
Any other white space or line breaks between the if..else statements make it so the new test won't pass. Would you mind updating the test to the following?
{
"text":
"You should have closing and opening curly braces for each condition",
"testString":
"assert(code.match(/if\\s*\\((.+)\\)\\s*\\{[\\s\\S]+\\}\\s*else if\\s*\\((.+)\\)\\s*\\{[\\s\\S]+\\}\\s*else\\s*\\{[\\s\\S]+\\s*\\}/), 'You should have closing and opening curly braces for each condition in your if else statement');"
},
This should allow for any amount of white space throughout the code while still requiring both curly braces. If possible, could you check this out locally on your end just to confirm it works? Let me know what you think and if you have any other ideas.
Please take a look at this section of the Contributor's Guide for how to update your PR and amend your git commit message. Also, feel free to reach out if you need any help with the process.
@scissorsneedfoodtoo i've made changes that you suggested. I also tested it locally and it works as expected.
:sparkles: :sparkles: :sparkles: Awesome! Congratulations on your first contribution to freeCodeCamp! :sparkles: :sparkles: :sparkles:
Thank you for improving this challenge, @devocija-it, and also for making those changes so quickly. We're all really looking forward to your next contribution.
Hi @QuincyLarson !
I've added a test for if else statements curly braces to ensure that every condition has to have both opening and closing curly braces.
ISSUES CLOSED: #17155
Description
I've added additional test case to Basic JavaScript: Introducing Else if statements challenge to ensure that every condition in in the else if statement has to have both opening and closing curly braces.
Issue Link
https://github.com/freeCodeCamp/freeCodeCamp/issues/17155
Pre-Submission Checklist
dev
branch.fix/
,feature/
, ortranslate/
(e.g.fix/challenge-tests
)npm test
.npm run commit
to generate a conventional commit message. Learn more here: https://conventionalcommits.org/#why-use-conventional-commitsChecklist:
Closes https://github.com/freeCodeCamp/freeCodeCamp/issues/17155