Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting From Many Options With Switch Statements-Incorrect #7231

Closed
itsmikewest opened this issue Feb 24, 2016 · 3 comments
Closed

Selecting From Many Options With Switch Statements-Incorrect #7231

itsmikewest opened this issue Feb 24, 2016 · 3 comments

Comments

@itsmikewest
Copy link

itsmikewest commented Feb 24, 2016

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

@ltegman
Copy link
Member

ltegman commented Feb 24, 2016

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!

@ltegman ltegman closed this as completed Feb 24, 2016
@itsmikewest
Copy link
Author

itsmikewest commented Feb 24, 2016

Awesome thanks!

Sent from my iPhone

On Feb 24, 2016, at 3:01 PM, Logan Tegman notifications@github.com 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.

@RomingArt
Copy link

RomingArt commented Jan 14, 2017

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);

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants