Cannot access variable declared outside of Switch Statement

Lneuner

I am declaring a variable contactNumber outside of a switch statement and then trying to assign it inside the switch statement. However, when it reaches the assignment, I get an error SyntaxError: Unexpected identifier on the assignment line executed inside the switch statement

function helplineContactMessageForCountryCode(countryCode) {

    var contactNumber = ''
    switch (countryCode) {
        case 'NG':
        contactNumber = '234-01-772-2200'
        break

        case 'UG':
        contactNumber = '0800-100-330'
        break

        case 'US'
        contactNumber = '1-800-232-4636'
        break

        case 'ZA':
        contactNumber = '0800-012-322'
        break

        default:
        //Return empty string if no country code is found
        return ''
    }
    return 'You can try calling the Toll-Free HIV and AIDS Helpline and speak to a human - ' + contactNumber
}
Christian4423

You are missing a : after the "US" case.

function helplineContactMessageForCountryCode(countryCode) {

  var contactNumber = ''
  switch (countryCode) {
    case 'NG':
      contactNumber = '234-01-772-2200';
      break;
    case 'UG':
      contactNumber = '0800-100-330';
      break;
    case 'US':
      contactNumber = '1-800-232-4636';
      break;
    case 'ZA':
      contactNumber = '0800-012-322';
      break;
    default:
      contactNumber = contactNumber;
      break;
  }
  return 'You can try calling the Toll-Free HIV and AIDS Helpline and speak to a human - ' + contactNumber
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java: how to access a variable which was declared inside a switch statement

From Dev

How to access a variable outside the if statement

From Dev

Assigned variable empty outside of switch statement PHP

From Dev

Assigned variable empty outside of switch statement PHP

From Dev

Why must a variable be declared outside of the scope of an if statement in order to exist?

From Dev

access PHP variable outside if/else statement

From Dev

access PHP variable outside if/else statement

From Dev

Cannot access variable outside function jquery

From Dev

How to access a Swift enum associated value outside of a switch statement

From Dev

Use variable outside switch statement + asp.net mvc

From Dev

Variable declared in sql statement But cannot get the data to show

From Dev

How to use JavaScript variable outside if-statement scope between two if-statements when it is declared in one of them?

From Dev

How to use JavaScript variable outside if-statement scope between two if-statements when it is declared in one of them?

From Dev

variable not updated outside if statement

From Dev

Ruby struct creation block cannot access variable outside the block

From Dev

Cannot access variable/property set with the If-else clause, outside of the clause

From Dev

Variable declared and not used in conditional statement

From Java

Why can't variables be declared in a switch statement?

From Dev

switch statement not changing a variable

From Dev

How to access to Webview declared in onCreate from outside?

From Dev

Access to types declared outside @model scope in MVC

From Dev

access outside variable in macro?

From Dev

access outside variable in macro?

From Dev

Use a variable declared in a function outside that function

From Dev

function access variable declared in decorator

From Dev

JavaScript Cannot access variable in multiple value return statement

From Dev

Variable assignment outside of case statement

From Dev

Variable value different outside of if statement

From Dev

Variable not declared, inside a if..else statement

Related Related

  1. 1

    Java: how to access a variable which was declared inside a switch statement

  2. 2

    How to access a variable outside the if statement

  3. 3

    Assigned variable empty outside of switch statement PHP

  4. 4

    Assigned variable empty outside of switch statement PHP

  5. 5

    Why must a variable be declared outside of the scope of an if statement in order to exist?

  6. 6

    access PHP variable outside if/else statement

  7. 7

    access PHP variable outside if/else statement

  8. 8

    Cannot access variable outside function jquery

  9. 9

    How to access a Swift enum associated value outside of a switch statement

  10. 10

    Use variable outside switch statement + asp.net mvc

  11. 11

    Variable declared in sql statement But cannot get the data to show

  12. 12

    How to use JavaScript variable outside if-statement scope between two if-statements when it is declared in one of them?

  13. 13

    How to use JavaScript variable outside if-statement scope between two if-statements when it is declared in one of them?

  14. 14

    variable not updated outside if statement

  15. 15

    Ruby struct creation block cannot access variable outside the block

  16. 16

    Cannot access variable/property set with the If-else clause, outside of the clause

  17. 17

    Variable declared and not used in conditional statement

  18. 18

    Why can't variables be declared in a switch statement?

  19. 19

    switch statement not changing a variable

  20. 20

    How to access to Webview declared in onCreate from outside?

  21. 21

    Access to types declared outside @model scope in MVC

  22. 22

    access outside variable in macro?

  23. 23

    access outside variable in macro?

  24. 24

    Use a variable declared in a function outside that function

  25. 25

    function access variable declared in decorator

  26. 26

    JavaScript Cannot access variable in multiple value return statement

  27. 27

    Variable assignment outside of case statement

  28. 28

    Variable value different outside of if statement

  29. 29

    Variable not declared, inside a if..else statement

HotTag

Archive