Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Adam Flanagan
8,022 PointsJavaScript help needed
Hi, I need some javascript help, I basically want the code to mean the same as this:
If var="12345", display page '12345.html' (then a list of similar statements but different numbers linking to different pages, but...) if var equals none of above numbers, display page 'error.html'
2 Answers
Adam Flanagan
8,022 PointsJim Hoskins can you help?
Stone Preston
42,016 PointsYou could use a switch statement.
switch(n)
{
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}
Adam Flanagan
8,022 PointsOkay, thanks