> I think one advantage of computers is that what you produce at the end has to work
No that's not true, that something works is beginner level stuff in many cases. In some cases you're right though, because what has been asked is a super tough problem to crack.
I'll showcase the moments in which the "it has to work" requirement is not enough.
To show this example, I already have to break 2 conventions that are a no no, in my opinion. To other devs: I'm commenting everything (I can't assume someone who works in law to know code, he/she might, he/she might not) and I'm using globals for easier variable reassignment, to ease the example for readability.
Let's get started. The requirement: print 5 to the console of your browser [1].
Open up Chrome Dev Tools (view -> developer -> developer tools -> console)
Type in the following:
five = 1 + 1 + 1 + 1 + 1 //compute 1 + 1 + 1 + 1 + 1 and save it in the computer with the name five
console.log(five) //outputs 5
five = 0 //reset
// loop 5 times, and every time the pc adds 1 to the saved part of the computer named five
for (loopCount = 0; loopCount < 5; loopCount = loopCount + 1) {
five = five + 1
}
console.log(five)
five = 5 //save the number 5 in the computer with the name five
console.log(five) //outputs 5
console.log(5) //also outputs 5
FIVE = 5 //all-caps is a convention for that something is a constant, like a constant number such as 5
console.log(FIVE) //outputs 5 as well, and also probably the way programmers want to see it.
Some of these methods have been really silly and if you catch that during an interview, you won't pass. People can point out that most of these methods happen one way or another, but not when you have a simple requirement such as "output 5". In fact, if that truly is the requirement, then I would go for:
console.log(5)
And I'd consider the first 2 entries totally nonsensical (unless I asked it with a funny voice or asked them to do whatever / be creative), the 4th entry slightly questionable but fine and the 5th entry fine.
[1] Read the following link to have some context about what the JavaScript console is. Don't worry about not understanding the code or the technical terms. You're not missing anything, as far as context is concerned, I checked. Read it until the first paragraph of "Running JavaScript".
https://developers.google.com/web/tools/chrome-devtools/cons...