A better way to doing if statements in JavaScript | #shorts

preview_player
Показать описание
#viral
Рекомендации по теме
Комментарии
Автор

In this particular case since you're returning integers 0 to 6, or -1, the ideal candidate is .indexOf() on an array

let days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
let dayValue = days.indexOf(day);

nagarajansubramani
Автор

additionally, if you are having the user enter the text, you need to force the case to match, in this case, lowercase it.

javabeanz
Автор

Programming in Java

const day



Programming in JavaScript

Now it makes sense.

StandingSalmon
Автор

Why not use an array since you're using a zero based index?

thepatternplayback
Автор

Don't ever do this way you dont exactly understand maps or you're noob. An author is noob here

portusdelphini
visit shbcf.ru