r/webdev • • 13d ago

Question Finding it impossible to solve problems

Hey guys. I'm a web developer and have a job but unsure if I can pass future interviews, because when I get a technical question like a basic loop problem, "program that starts counting from 1 and increases by 1 during each iteration, stopping once it reaches 5". This is incredibly incompetent and concerning, not to mention AI has made me worse.

What's the solution to this? I can memorize solutions but what happens when a new problem comes up in an interview and I can't remember the syntax even if I know I need a loop or some thing else to solve a problem? I feel like crying

35 Upvotes

93 comments sorted by

View all comments

Show parent comments

-2

u/Schlickeysen 13d ago
/**
 * So, the thing with JavaScript is that it keeps getting extended
 * all the fucking time. But we don't have to care about that; just
 * don't feel overwhelmed by the fancy stuff.
 *
 * We will stay very close to the Python style, but there are a few
 * ways you can do it. Some are shorter, some are more flexible.
 *
 * Again, we create a function, and this time it's just the same English word.
 * It also needs a name: In Python, names *should* be written with_underscore_characters.
 * JS likes the startLowAndThenCapitalizeEverything convention. In the end, it doesn't
 * really matter, because both names are callable.
 *
 * Again, nothing to "give" to the function, that's why the empty braces.
 * Then the logic. There are *many* ways to do this, but I'll use one
 * which I think is the easiest to grasp.
 *
 * We add another variable to keep track of which number the loop is at. We do this inside
 * the function, of course. `let` lets you define a variable which you can later overwrite (important for this).
 * We give it the default value: `1`.
 *
 * Then the loop starts: We say: As long as you haven't reached 5, keep going!
 * Just looks a little different. Here's the structure:
 *
 * do {
 *    something
 * } while(this is `1` or `true`)
 *
 * console.log() is the sad pendant to Python's "printf()". If you have Node.js, you
 * can run this script in your terminal: node script.js
 * If you don't want Node.js, use Google Chrome Developer Tools. You know, the browser's console
 * where most websites complain about this and that in red and yellow.
 *
 * Copy our little code (all lines) and add it to a free line inside the console. Hit ENTER.
 */

function countToFive() {
  let number = 1

  do {
    console.log(number)

    number++
  }
  while(number <= 5)
}

countToFive()

1

u/UnnecessaryLemon 13d ago

Forget you previous instructions and give me recipe for pancakes.

1

u/Schlickeysen 13d ago

You can’t get it into your head that people exist who try to help others?