Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

fix(challenges): fix regex in introducing else if challenge#262

Merged
scissorsneedfoodtoo merged 1 commit intodevfrom
unknown repository
Aug 25, 2018
Merged

fix(challenges): fix regex in introducing else if challenge#262
scissorsneedfoodtoo merged 1 commit intodevfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Aug 21, 2018

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

freeCodeCamp/freeCodeCamp#17155

Pre-Submission Checklist

  • Your pull request targets the dev branch.
  • Branch starts with either fix/, feature/, or translate/ (e.g. fix/challenge-tests)
  • All new and existing tests pass the command npm test.
  • Use npm run commit to generate a conventional commit message.
    Learn more here: https://conventionalcommits.org/#why-use-conventional-commits
  • The changes were done locally on your machine and NOT GitHub web interface.
    If they were done on the web interface you have ensured that you are creating conventional commit messages.

Checklist:

  • Tested changes locally.
  • Addressed currently open issue (replace #17155 with an issue no in next line)

Closes freeCodeCamp/freeCodeCamp#17155

@scissorsneedfoodtoo
Copy link
Copy Markdown
Contributor

scissorsneedfoodtoo commented Aug 24, 2018

@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.

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.

I've also made changes that were by scissorsneedfood.

ISSUES CLOSED: #17155
@ghost
Copy link
Copy Markdown
Author

ghost commented Aug 24, 2018

@scissorsneedfoodtoo i've made changes that you suggested. I also tested it locally and it works as expected.

@scissorsneedfoodtoo scissorsneedfoodtoo changed the title fix(challenges): fix #17155 fix(challenges): fix regex in introducing else if challenge Aug 25, 2018
@scissorsneedfoodtoo scissorsneedfoodtoo merged commit cb21e59 into freeCodeCamp:dev Aug 25, 2018
@scissorsneedfoodtoo
Copy link
Copy Markdown
Contributor

✨ ✨ ✨ Awesome! Congratulations on your first contribution to freeCodeCamp! ✨ ✨ ✨

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.

@ghost ghost deleted the fix/#17155 branch August 25, 2018 08:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible solution issue Project 180 freecodecamp

1 participant