Backtick strings not accepted

Hello Everyone, this is my first post here and I’m asking for help.
This is confusing.
I am at the " Redux: Use const for Action Types" lesson and here’s my code:

When I use single or double quotes for my strings inside const declarations, it works fine. But if I switch to backticks, it doesn’t work.
Also, it doesn’t work with this format either:
const LOGIN = “LOGIN”, LOGOUT = “LOGOUT”;

Your code so far


// change code below this line
const LOGIN = `LOGIN`;
const LOGOUT = `LOGOUT`;
// change code above this line

const defaultState = {
authenticated: false
};

const authReducer = (state = defaultState, action) => {

switch (action.type) {

  case LOGIN:
    return {
      authenticated: true
    }

  case LOGOUT:
    return {
      authenticated: false
    }

  default:
    return state;

}

};

const store = Redux.createStore(authReducer);

const loginUser = () => {
return {
  type: LOGIN
}
};

const logoutUser = () => {
return {
  type: LOGOUT
}
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36.

Challenge: Use const for Action Types

Link to the challenge:
https://www.freecodecamp.org/learn/front-end-libraries/redux/use-const-for-action-types

That is just how the test is set up and checks for the strings. It can be updated to accept backticks but I’m not sure why you would need to use backticks for this.

In fact, in “real code” seeing a template literal without any real reason for it might potentially be confusing to a reader and lead to speculation about code missing or some other bug. I know there are people that use template literal for all strings, but personally I’m not sure it is such a good idea for the reason I just mentioned.

Test code, in case you are curious:

getUserInput => assert((function() {  const noWhiteSpace = getUserInput('index').toString().replace(/\s/g,''); return (noWhiteSpace.includes('constLOGIN=\'LOGIN\'') || noWhiteSpace.includes('constLOGIN="LOGIN"')) && (noWhiteSpace.includes('constLOGOUT=\'LOGOUT\'') || noWhiteSpace.includes('constLOGOUT="LOGOUT"')) })());
1 Like

Thank you a lot for taking your time to reply to my question.
Now I understand how did it go!
I’ll take by your advice about when to use ES6 template literals and when not.
Thanks again!

It might be ok to allow all single/double quotes and bacticks. We could also simplify the test’s testString at the same time.

const noWhiteSpace = code.replace(/\s/g, ''); assert(/constLOGIN=('"`)LOGIN\1/.test(nonWhiteSpace) && /constLOGOUT=('"`)LOGOUT\1/.test(nonWhiteSpace));

Simplifying the test is never a bad idea. And I guess it wouldn’t hurt to allow backticks.

@marsou001 Would you like to contribute to FCC by updating the test referenced above to accept backticks?

I would realy like to but I don’t think I’ll be able to at the moment.

@RandellDawson Maybe we should open an issue and tag it with first timers welcome and help wanted, just to let someone give it a go?

@RandellDawson I can’t assign labels, I don’t have write access. Should I make the issue anyway or will you do it?

@RandellDawson Issue opened https://github.com/freeCodeCamp/freeCodeCamp/issues/38341

1 Like

Create the issue and I will add the applicable labels to it.