Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other What code is this?

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #173328
    chrisburton
    Participant

    Anyone have any idea what code this entails? http://www.stanford.edu/class/cs101/code-1-exercises.html

    I thought it was Javascript but after testing, something entirely different happens (e.g. print() brings up the printer settings).

    #173329
    nixnerd
    Participant

    Looks like Python… save for the semicolons.

    #173335
    Paulie_D
    Member

    I hit the backlink at the top of the page and it seems to be a javascript course.

    EDIT –

    Aha

    Note “print” is not a normal part of Javascript, I added it for CS101

    #173337
    chrisburton
    Participant

    @Paulie_D Where do you see that quote?

    I find it completely stupid to teach print();as if it actually does what it shows when it actuality, it doesn’t. It’s just confusing. After briefly reading through some docs it states that print(); is a function so that is why it’s acting comparable to document.write();.

    #173339
    Paulie_D
    Member

    I hit the backlink and then selected the introduction link.

    When he first demos ‘print’ in the first code example, it’s the last comment in the green boxed”notes”.

    #173340
    chrisburton
    Participant

    Gotcha. Thanks.

    #173348
    __
    Participant

    I find it completely stupid to teach print() as if it actually does what it shows when it actuality, it doesn’t.

    Well, it does do what it shows. It’s just not a native JS function: it’s a user-defined function.

    Here’s it’s definition, if you’re interested:

    // Print any number of things, separated by spaces and ending with a carriage return.
    function print() {
      // printlimit feature
      if (window.globalPrintCount <= 0) {
        if (window.globalPrintCount == 0) {
          printOne("***print output limited***");
          printOne("<br>");
          window.globalPrintCount--;
        }
        return;
      }
      window.globalPrintCount--;
        
    
     for (var i=0; i<arguments.length; i++) {
       printOne(arguments[i]);
     }
     printOne("<br>");
    }
    

    [JavaScript] syntax is strict and narrow

    LOL

    #173353
    chrisburton
    Participant

    Well, it does do what it shows. It’s just not a native JS function: it’s a user-defined function. @traq

    What I mean is that print() seems to already be native to JS (from my testing it opens printer settings) so creating a user-defined function to change that seems kind of stupid to teach because it can be confusing.

    #173354
    __
    Participant

    What I mean is that print() seems to already be native to JS (from my testing it opens printer settings)…

    Ha! Was not aware of that. Upon research, it seems it’s not part of any spec, but is supported basically everywhere. Given this, yes, I agree that creating a UDF named print is “kind of stupid.”

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Other’ is closed to new topics and replies.