How do I handle JS (or other computer science problems) I'm not sure how to solve?


#1

Question

How do I handle JS (or other computer science problems) I’m not sure how to solve?

Answer

Try pseudo-coding the problem! Pseudo-code is a written outline of the steps to solve your JavaScript/computer science/programming problem.

Although there are no set rules for how to pseudo-code, you may find it helpful to write this outline in the same text editor where you will use code to solve the problem. Then write the step-by-step process for how to solve the problem (in whatever human language :wink: you are fluent in) starting with the purpose of the program. Then write the solve to the problem one statement per line that expresses one action for the code to solve, we also want to write our pseudo-code like we would normal code, as in there should blocks of pseudo-code, lines should be indented when they are not part of a new block, coding keywords should be used, etc. After the pseudo-code is completed we will then fill in the “real” code version of what each line of our pseudo-code tells us to do - we can always look up the syntax/how to write our pseudo-code in the computer language of our choice when necessary.

Pseudo-code example problem:

//Problem to solve: For the following array of names, ['Laurel', 'Henry', 'Fallon', 'Anthony', 'Alex'],  log `Hello` plus the name to the console.

Pseudo-code start:

//This program will loop through an array of names and print `Hello` plus the current name in the array to the console

//Initialize a variable `array` to the given array of names

//loop through the array variable

  //on each loop of the array log `Hello ` plus the current name in the array to the console

Pseudo-code with code:

//This program will loop through an array of names and print `Hello` plus the current name in the array to the console

//Initialize a variable `array` to the given array of names
const array = ['Laurel', 'Henry', 'Fallon', 'Anthony', 'Alex'];

//loop through the array variable
for (let i = 0; i < array.length; i++){

  //on each loop of the array log `Hello ` plus the current name in the array to the console
  console.log(`Hello ${array[i]}`);
}