Jump to content

mykstor

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by mykstor

  1. 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...
×
×
  • Create New...