Freecodecamp: Selecting From Many Options With Switch Statements-Incorrect

Created on 24 Feb 2016  ·  3Comments  ·  Source: freeCodeCamp/freeCodeCamp

FreeCodeCamp Issue template

To Use this Template:

  • Fill out what you can
  • Delete what you do not fill out

NOTE: ISSUES ARE NOT FOR CODE HELP - Ask for Help at https://gitter.im/FreeCodeCamp/Help

Issue Description

  • I believe I found an issue with the description for testing case values. The module states that "case values are tested with a strict equality operator (===). I think this may be incorrect. My reasons are as follow:

1.) When using strict equality operators the Javascript console, the console flags these and provides and red error X. The code will not run using a strict equality operator.
2.) The W3C examples http://www.w3schools.com/js/js_switch.asp show an assignment operator being used, which my code below also uses and passes the test.

I'm still learning, but hopefully this helps and the corrections can be made. Thanks!

Browser Information

  • Google Chrome, Version 48.0.2564.109 (64-bit)
    *OSX

    Your Code

function myTest(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    case 1: 
      answer = "alpha";
      break;
    case 2:
      answer = "beta";
      break;
    case 3:
      answer = "gamma";
      break;
    case 4:
      answer = "delta";
      break;
  }
// Only change code above this line  
  return answer;  
}

// Change this value to test
myTest(1);

Screenshot

screen shot 2016-02-23 at 6 42 27 pm

Most helpful comment

case values are tested with a strict equality operator (===)

means that

 switch (val) {
    case 1: 

is equivalent to if (val === 1) not that everything inside your case needs to be strict equality.

Please visit the Help Chat if you need further clarification. Thanks and happy coding!

All 3 comments

case values are tested with a strict equality operator (===)

means that

 switch (val) {
    case 1: 

is equivalent to if (val === 1) not that everything inside your case needs to be strict equality.

Please visit the Help Chat if you need further clarification. Thanks and happy coding!

Awesome thanks!

Sent from my iPhone

On Feb 24, 2016, at 3:01 PM, Logan Tegman [email protected] wrote:

case values are tested with a strict equality operator (===)

means that

switch (val) {
case 1:
is equivalent to if (val === 1) not that everything inside your case needs to be strict equality.

Please visit the Help Chat if you need further clarification. Thanks and happy coding!


Reply to this email directly or view it on GitHub.

I looke at the code above but was not able to make the code work with strict equality but this is my code if people have questions or think it is wrong please leave me a comment.
`
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val) {
case 1:
answer = "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
break;
}

// Only change code above this line
return answer;
}

// Change this value to test
caseInSwitch(2);

`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vaibsharma picture vaibsharma  ·  3Comments

MichaelLeeHobbs picture MichaelLeeHobbs  ·  3Comments

robwelan picture robwelan  ·  3Comments

Tzahile picture Tzahile  ·  3Comments

QuincyLarson picture QuincyLarson  ·  3Comments