• Jonathan (unregistered)

    If I had been given that task I would have made a result to percentage "map"/"dictionary". This would have allowed one to easily scan the relationship between the values and only have to write a single formatted alert. Overall would have been more readable to me.

  • Bilateralrope (unregistered)

    The first question I have when seeing that logic is if the result is limited to one decimal place elsewhere.

  • L (unregistered)

    those == comparisons on what looks like stringified floating point numbers are actually killing me. twice.

  • King (unregistered)

    Am I eligible to be held for moderation?

  • King (unregistered) in reply to King

    Guess not. I failed.

  • Tinkle (unregistered) in reply to King

    Everything in moderation.

  • Sauron (unregistered) in reply to King

    You're unregistered xD

    Allowing an unregistered user to moderate one's website would be a serious WTF, and I don't think Remy Porter wants to be the WTF of the next Feature Article.

  • (nodebb)

    And this leads me to my second suspicion: the mapping of result to "percentage" is utterly arbitrary.

    Plotting them seems to concur with this - it's straight or uniformly curved almost nowhere along the plot...

    • https://imgur.com/a/XfxVuln
  • WTFGuy (unregistered)

    Setting aside who is held for moderation and why (and whether I will be too) ...

    I like that we are comparing result which is logically a number regardless of its JavaScript datatype, to a decimal value with tenths expressed as a string. And using == which invites all sorts of floating point not-quite-equals errors.

    In fact I'll bet that that page actually "works" for the majority of result values because all the == tests always fail due to floating point conversion / non-rounding issues and no alert() is displayed. But for some rare value, the one Gracie's friend got, the alert() triggers and the page stops.

    I suppose another possible WTF we can't see here is that results might possibly conceivably actually be a stringly value as this code snip is executing. Which might not have quite the same format as the right side of the == comparisons expect.

    Implicit type conversion and stringly everything is such an obstacle to correctness you'd almost think it (and much of the rest of JavaScript) was invented by somebody actively trying to sabotage the WWW.

  • (nodebb)

    That's what happens when you hire programmers who are bad at math.

  • (nodebb)

    They must really be needing teachers for maths and programming.

  • Tim R (unregistered)

    taking into account the old adage "Never attribute to malice that which is adequately explained by stupidity"

    in this case I don't see how the relationship between "result" and "average" could possibly be explained by stupidity so I'm forced to the conclusion that malice is the only explanation

  • Darren (unregistered)

    That the alert says "you must have a minimum average of 68.0 %" for values over 68% would put this in line for a place in this weekend's Error'd.

  • RLB (unregistered) in reply to Domin Abbus

    That's what happens when you hire programmers who are bad at math.

    It's what happens when you hire admissions managers who are bad at math, and middle managers who force programmers to use this bad math even if the programmers know better.

  • Dave Aronson (github) in reply to King

    Why, do you need a hug? ;-)

  • (nodebb) in reply to Sauron

    I think @King was saying that he wanted to be moderated. My advice is that there are surely some nice women somewhere in town who'd be willing to pay him a visit dressed in black PVC and moderate him.

  • (nodebb) in reply to Sauron

    I don't think Remy Porter wants to be the WTF of the next Feature Article.

    It happens quite frequently enough already.

  • (nodebb)

    I think the spreadsheet idea is probably correct. Too many people are assuming that result is a number. It may as well be a row/column index where each cell gives the percentage. God knows what workflow is used to get that information.

  • (nodebb)

    If this is university code it's very likely that it was written by some first or second year student who had taken a javascript course and who was paid slightly more than minimum wage to convert a spreadsheet into a script.

    (After working at universities for decades you see two types of code - core function code like HR and course assignments where they've either outsourced it or still have their own in-house team to maintain and extend what they have, and everything else where some student or staff member who doesn't have any real programming experience but has a few courses under their belt gets paid to slam something together. There's rarely anything in between.)

  • Anon55 (unregistered) in reply to L

    Well... If result is a floating point, then that code is horribly broken due to rounding errors. If it's all strings, it has a chance of being somewhat correct.

  • Sou Eu (unregistered)

    The "calculated average" seems to simulate what percentage of applicants did worse than the one whose results are shown. Someone who scored 0.9 is in the bottom 49% of applicants while someone who scored 2.5 is in the top 31.5% (100 - 68.5). Could these "results" be a skewed standard deviation (sd)?

    1. If JavaScript thinks it can be a number, it's treated as a number. Let's get rid of those quotes!
    2. Those conditions should check for less-than-or-equal instead of strictly equal and each subsequent check should start with "else if" instead of "id". (gets rid of discrete gaps in floating point numbers).
    3. The alert messages are all the same except for the applicant's score. The conditions should set a variable to the right percentage and have this message constructed and displayed at the end.
    4. This page doesn't even indicate of the applicant passed; the applicant has to manually compare their "calculated average" to 68%
  • LZ79LRU (unregistered) in reply to Sou Eu
    Comment held for moderation.

Leave a comment on “Teaching Programming”

Log In or post as a guest

Replying to comment #:

« Return to Article