1

I am trying to set values to my firebase realtime database and I have the following code for that. It should work, but it does not. All I can get is

Uncaught SyntaxError: Unexpected token .

On every if statement line. I am not sure why is this happening.

firebase.database().ref('users/' + userId +"/settings").set({
  if (publicCountryYes.checked) {
    publicCountryFirebase: true;
  }else{
    publicCountryFirebase: false;
  };
  if (publicCompanyYes.checked){
    publicCompanyFirebase: true;
  }else{
    publicCompanyFirebase: false;
  };
  if (publicEmailYes.checked){
    publicEmailFirebase: true;
  }else{
    publicEmailFirebase: false;
  };
  if (publicInterestsYes.checked){
    publicInterestsFirebase: true;
  }else{
    publicInterestsFirebase: false;
  };

  if (publicNameYes.checked){
    publicNameFirebase: true;
  }else{
    publicNameFirebase: false;
  };
  if (publicPhoneYes.checked){
    publicPhoneFirebase: true;
  }else{
    publicPhoneFirebase: false;
  };
});
1
  • Are you trying to create an object with each keys values set based on a conditional? Like this? set({ publicEmailFirebase: publicEmailYes, etc... }) Commented Oct 14, 2017 at 11:46

1 Answer 1

1

The syntax is invalid, I'd suggest you can use something more concise:

firebase.database().ref('users/' + userId + "/settings").set({
    publicCountryFirebase: publicCountryYes.checked,
    publicCompanyFirebase: publicCompanyYes.checked
    // etc
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.