Похожие чаты

Hello everyone! Please help me, how to convert a string

to a number at the return?

Near the prompt, I can't put "+" because after that 0 is showing as an empty string. The task is: Force the user to enter a number from the keyboard (not a string and not NaN).

function getNumber() {

let num;
do {
num = prompt("Enter number", '');
} while (!isFinite(num) || num === "");
if (num === null || num === "") return null;
console.log("Number! Yes!");
return +num;
;


}
getNumber();

3 ответов

13 просмотров
Anna-Anna Автор вопроса

Thank you! But in anyway it's a string 😬😬😬🥺 When I do hover on the num it's showing a string😕

Anna Anna
screenshot Thank you! But in anyway it's a string 😬😬😬🥺 When I...

parseInt tries to convert the provided argument to an string, indeed the variable num is of type string, but what you have to look after is the returned value of the function getNumber

Anna Anna
screenshot Thank you! But in anyway it's a string 😬😬😬🥺 When I...

You can also learn about the function Number, Google it and see how it works

Похожие вопросы

Обсуждают сегодня

Вопрос по диагностике ошибок (я знаю в чем, в данном конкретном примере, я знаю, как исправить, пример модельный, понятно, что в реальности бывает намного запутаннее). module...
ⰄⰎⰋⰐⰐⰑⰛⰤⰧⰧⰩⰄ ⰊⰑⰁⰓⰡⰛⰦⰕⰫ
10
А дальше что?.. Записать в файл, потом в Код?.. И потом разбирать как-то?..
Хаскель Моисеевич Гопник
14
Asus, норм фирма для ноутов?
Артем Записной
20
А чем вам питонисты не угодили?😂
.
79
И ещё - определить, имеет ли он доступ к интернету очень просто - смотрим всех пользователей сети. И да, как оно без сети передаст данные в куда то?
BytePixel 🐧
15
Есть какой-нибудь для Delphi/FPC T*Compression(Decompression)Stream на базе LZ4/Zstd/любой другой быстрый(и хорошо сжимающий) алгоритм А ещё лучше в pure pascal А ещё лучше од...
notme
48
EMERGENCY 🚨Hi y’all can anyone help? - I accidentally bought wTLOS instead of regular TLOS, I am trying to swap it for regular TLOS or ethereum but am getting hit with 75% gas...
Marco
7
Ясн. Но я всеравно к кедам отношусь с опасением. Чисто субьективное кедосозерцание. Что касаемо "восторга изяшности кед" так и не вкурил, хотя много слышал, пока не поставил с...
Артем Записной
30
Hey everyone! How can I pass string from Rust to c++ function that expects std::string? When I'm passing CString the c++ functions tell that the string is empty
Jacob
16
Hey guys, did you see the new announcement about $Fun? 🔥
Filip Murphy
55
Карта сайта