简体   繁体   中英

How do I convert an integer to a string in JavaScript?

function seven_boom() {
var a = window.prompt("Enter Number:");
var b = Number(a) / 7;
var c = b.toString();
var d = c.includes(".");
if (d=="true") {
alert("BOOM!");
}}

I want to convert b to string and I tried the code above this text and its doesn't work.... Please help me:)

d is a boolean, so it's value will be true or false whereas you're checking if d is a string and has value "true"

 function seven_boom() { var a = window.prompt("Enter Number:"); var b = Number(a) / 7; var c = b.toString(); var d = c.includes("."); // The output of this line is a boolean if (d) { alert("BOOM;"); }} seven_boom();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM