Jump to content

I find your explanations too complicated


graphicsgeezer

Recommended Posts

I used to use W3 schools a lot but lately have found your explanations overly complicated. For example, the php upload script is almost unintelligible. After a few hours I finally managed to break it down to two lines from about 100.

 

Same for dozens of other explanations. Recently I wanted to look up how to create a refresh script so I could redirect the reader to another site. I couldn't find anything.

 

So I googled Refresh Tag and found an explanation instantly in W3.org.

 

 

 

 

Link to comment
Share on other sites

A lot of the W3School material has recently been updated -- but I would be very surprised if you found large portions of examples to be unnecessary. I would be interested to see a few examples of your code simplifications.

 

The Php file upload example does include some common-sense validations... and if you eliminate them and someone then uploads a file that shuts down or destroys your website you might develop an appreciation for them. Maybe this is not the example you are referring to?

 

http://www.w3schools.com/php/php_file_upload.asp

Link to comment
Share on other sites

I used to use W3 schools a lot but lately have found your explanations overly complicated. For example, the php upload script is almost unintelligible. After a few hours I finally managed to break it down to two lines from about 100.

 

Same for dozens of other explanations. Recently I wanted to look up how to create a refresh script so I could redirect the reader to another site. I couldn't find anything.

 

So I googled Refresh Tag and found an explanation instantly in W3.org.

 

 

 

 

Which example(s) are you referring to? And which parts do you consider superfluous?

Link to comment
Share on other sites

I'm 65 and just now learning javascript. I'm not sure exactly where I should put suggestions for improvements on specific javascript example pages.

Here or under the topic "javascript"? I don't want to cross-post. Meantime, I'll try here:

 

I find that bloggers and websites –not just w3schools– often introduce javascript concepts with examples that are clever and fruit-filled, but are either too specific for me to adapt in a broader sense –or on the other hand, so general that they remain inscrutible.

 

I want to use javascript's "switch" for a group of conditions, but after contemplating the examples at length, how to compose the (statement) and how to label or denote the cases remains a head-scratcher for me. I'm referring to:

 

http://www.w3schools.com/js/js_switch.asp

Syntax:switch(expression) {  case n:                code block                break;            case n:                code block                break;         ...etc...  }

With no prior knowledge, a newbie can't know what the instructor means by n. Is n meant to be a label? If so, could it be in quotes? Or is n meant to be a unique result? Could it even be a function? One might even infer that all cases could be designated with the same n. Often n means "a number". So, must each case be a sequential number starting with 0? But I wonder, because if they're always numbered this way starting with zero, why would one need to designate them at all? So perhaps that's not right...

 

The next example replaces all the same n's with numbers for the days of the week. At least here, the cases look unique. But this, too, is confusing because the cases end up being denoted the perfect sequence of intergers from 0 to 6. As a result, I still don't see how to designate them in a broader sense.

Example:Use today's weekday number to calculate weekday name: (Sunday=0, Monday=1, Tuesday=2, ...)switch (new Date().getDay()) {    case 0:        day = "Sunday";        break;    case 1:        day = "Monday";        break;    case 2:        day = "Tuesday";        break;    ... etc ...

This example above shows all the n's replaced with sequential intergers 0 - 6 for the days of the week. I think these are supposed to be possible products of (statement)...

...or must one enumerate cases sequentially?

Could each case be denoted willy-nilly such as "hot", "cold", 3, ab, if (arr.length == 7) or myFunction( ); ?

Furthermore, it seems to me the choice of a blackbox built-in javascript method for the example statement only adds to the puzzlement about what other kind of statement one could write there.

 

Thank you for taking a look at this page and perhaps finding someone who might see how to make it more useful.

Meanwhile, I guess I'll have to hold off on using "switch" and stick with my laundry list of if's, else if's and elses.

 

Mykstor in AZ

I can't figure out how to delete this last pretty print box. Can't get a cursor beyond it to highlight it. Curious...
Link to comment
Share on other sites

Most W3Schools examples allow you to "Try It" and can easily be modified to further establish how something works. You can change the code and then submit it and run it again...

 

http://www.w3schools.com/js/tryit.asp?filename=tryjs_switch

 

Also for specifics of a particular language item it is often helpful to look at other online references...

 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch

 

http://msdn.microsoft.com/en-us/library/ie/hzc6t81t%28v=vs.94%29.aspx

Link to comment
Share on other sites

W3Schools isn't perfect. If the way they explain things doesn't work for you you can look at other websites. My knowledge comes from a large variety of sources.

 

 

The switch statement looks at a variable and compares it to any values you want it to. The value can be anything: a literal value ("red", 5 and true are literal values), a variable or even a function name.

 

Here are some examples of how to use the switch() statement. The second example shows a situation where switch() is easier to use than a series of if() statements.

var color = "blue";var singleDigit = 5;switch(color) {    case "red":        alert("Red was the chosen color");    break;    case "green":        alert("Green was the chosen color");    break;    case "blue":        alert("Blue was the chosen color");    break;}switch(singleDigit) {    case 0:    case 2:    case 4:    case 6:    case 8:        alert("The number is even");    break;    case 1:    case 3:    case 5:    case 7:    case 9:        alert("The number is odd");    break;}
Link to comment
Share on other sites

The switch statement looks at a variable and compares it to any values you want it to. The value can be anything: a literal value ("red", 5 and true are literal values), a variable or even a function name.

I'll try to be even more general. The switch evaluates a series of expressions until it finds a match, and then it executes the statements for that match. The expressions could be anything that evaluates to a value. That's fairly vague, most examples of a switch have it testing a variable, and then looking for literal values that match the value of the variable. That's what Ingolme showed, testing a variable against multiple values. But switches could be used in other ways that might look strange. The key concept is that it will test values and, if it finds a match, it will execute a block of statements (until it reaches a break statement). This switch statement will match any of the function calls that returned the value 5:
switch (5) {  case function1():    // if function1 returned 5, execute this  break;  case function2():    // if function1 did not return 5, but function2 did, execute this  break;  case function3():    // if neither of the above functions returned 5, but function3 did, execute this    // there's no break statement here, so if function3 returned 5 it will not     // stop executing at this point  case function4():    // it will execute these statements if function3 returned 5, or if none of the other     // functions returned 5 but function4 did  break;}
A structure like that is a little more interesting. One of the reasons is that a side effect of doing that will cause it to execute one or more of those functions, possibly doing other work, in the course of finding one that matches the switch value. One thing I'm not sure of and I haven't tested - if function3 returns 5, since there is no break statement there, I'm not sure whether it will also execute function4 or if it will skip that and just execute the next block of statements under that case label. I believe it will execute function4 and then execute the next block regardless of the return value, but I haven't tested that.That's just an example to try and show the general nature of a switch statement - you have an expression that evaluates to a value, and you have multiple cases which also evaluate to a value, and it will start executing code for the cases that match the value. If it finds a break statement, it will stop executing at that point and break out of the switch. If there's no break statement, if it finds another case label but the value doesn't match it will still continue executing until it finds a break statement. You can also have a default case if none of the others match:
var num = 3;switch (num) {  case 1: alert(1); break;  case 2: alert(2); break;  default: alert('this will run if nothing else matched');}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...