You can also watch a popular JavaScript basics crash course video on Youtube.
Video - https://www.youtube.com/watch?v=hyYbs3SANRo
Ensure that your code indentation is good. Submitting code that looks like the example given is unprofessional and makes it difficult to read for you as well as anyone who has to work with your code.
Bad indentation:
function problem1(inventory,passid){
if(Array.isArray(inventory)){
return inventory;}
else{
return [];
}
}
module.exports=problem1;Good indentation:
function problem1(inventory, passid) {
if(Array.isArray(inventory) && passid<50) {
return inventory;
} else {
return [];
}
}
module.exports = problem1;An easy way to indent your code is to press Ctrl + Shift + I in VSCode.
If you are on a Mac, try Cmd + Shift + I
Ensure that your variable names are descriptive. Variables names looks like the examples below are unprofessional and makes it difficult to read for you as well as anyone who has to work with your code.
Bad Naming:
const a = [1, 2, 3, 4, 5];
const a1 = [1, 4, 9, 16, 25];Good naming:
const numbers = [1, 2, 3, 4, 5];
const squares = [1, 4, 9, 16, 25];This also applies to functions
Bad Naming:
const numbers = [1, 2, 3, 4, 5];
function calc(n) {
return n * n;
}
const squares = numbers.map(calc);Good naming:
const numbers = [1, 2, 3, 4, 5];
function squareNumber(number) {
return number * number;
}
const squares = numbers.map(squareNumber);Naming is tricky for every engineer. But that does not mean you don't do it. It means you think about what to name it while you are writing code, not after you have finished.
Keeping your code as readable as possible will ensure that you don't run into issues later on. One way to ensure this with if else if is to always use {} with the statements.
Bad Usage:
let sum = 10;
if(value %2 == 0)
sum += value;
else if(value == 0)
sum += 1;
else
sum += -1;Good usage:
let sum = 10;
if(value %2 == 0) {
sum += value;
} else if(value == 0) {
sum += 1;
} else {
sum += -1;
}This ensures that there is never any confusion about which code runs and when.
It also ensures that there will be no chance of code not getting executed because it was placed on an adjacent line and is missed by the interpreter.