Answer the question
In order to leave comments, you need to log in
What's wrong with parsing?
It gives me null at the first check
function parseGuess(guess) {
var alphabet = ["A", "B", "C", "D", "E", "F", "G"];
if (guess === null || guess.lenght !== 2) {
alert("Стрелять нужно по координатам в формате А2 и т д, и не выпендриваться!");
}
else {
firstChart = guess.charAt(0);
var row = alphabet.indexOf(firstChar);
var column = guess.charAt(1);
if (isNaN(row) || isNaN(column)) {
alert("Слушай, это вообще мимо доски. Там нет кораблей!");
}
else {
return row + column;
}
}
return null;
}
console.log(parseGuess("B2"));
Answer the question
In order to leave comments, you need to log in
length, not length. Well, you don’t have firstChar, but there is firstChart
PS Well, when you check row, in order to display a message that “past the board”, you need to check not for NaN, but for < 0, since the expression
if it finds an element in the array will return it position, if not -1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question