I am just beginning with JavaScript and what I am trying to achieve now is to add bold style to a variable result. The code that I am refering to is the following:
if(isNumeric(n)) {
document.write("The square root of " + n + " is " + answer);
}
else {
alert('This is not a number!');
}
I want to make the variable answer
to appear in bold and the result to look like this:
Example: The square root of 4 is 2
Thank you all in advance!
It's just a matter of adding some HTML ?
if(isNumeric(n)) {
document.write("The square root of " + n + " is <strong>" + answer + "</strong>");
} else {
alert('This is not a number!');
}
This is fine for testing, but in production you wouldn't really use document.write
, and preferably you'd use an external stylesheet and a wrapper element to make parts of the text bold.
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.