How to make a part of a string bold?

the tasks below shall be completed using Web Document API functions and using neither the innerHTML nor the innerText property.

I want to bold just the violation part of the string in str3.

The only things I can find are using innerHTML which isn’t allowed.

Here is my JavaScript code:

// Find the placeholder node in the HTML document
const div0 = document.getElementById("part0");

// Create a new H2 and its text
const h0: HTMLHeadingElement = document.createElement("h2");
const h0text: Text = document.createTextNode("Part 0");
h0.appendChild(h0text);
div0?.appendChild(h0);

// Create a paragraph as its text
const par0: HTMLParagraphElement = document.createElement("p");
var str1 = ("Random");
var str2 = (" Random");
var str3 = ("someone else is a violation of academic honesty.");
var bold1 = ["violation"];


const par0text: Text = document.createTextNode(str1 
    + str2 
    + str3);
par0.appendChild(par0text);
div0?.appendChild(par0);

and here is my HTML code:

    <html>
  <head>
    <script src="./part0.ts" defer>
    </script>
    <link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
    <link rel="stylesheet" href="mystyle.css" />
  </head>
  <body>
    <div id="mocha"></div>
    <div id="part0" class="result"></div>
    <script src="https://unpkg.com/chai/chai.js"></script>
    <script src="https://unpkg.com/chai-dom/chai-dom.js"></script>
    <script src="https://unpkg.com/mocha/mocha.js"></script>
    <script class="mocha-init">
      mocha.setup("bdd");
      mocha.checkLeaks();
    </script>
    <script src="./mocha-checker.ts"></script>
    <script class="mocha-exec">
      mocha.run();
    </script>
  </body>
</html>

30 thoughts on “How to make a part of a string bold?”

  1. 223484 704148This really is such an excellent resource that you are offering and you give out at no cost. I appreciate seeing sites that realize the worth of offering a perfect helpful resource entirely free. I genuinely loved reading your submit. 197576

    Reply
  2. What i do not realize is in truth how you
    are now not really a lot more well-appreciated than you
    may be right now. You’re very intelligent. You understand thus considerably in the case of this subject, produced me for my part believe it from a lot of numerous angles.
    Its like women and men aren’t involved except it is something to accomplish with Girl gaga!
    Your individual stuffs great. All the time care for it up!

    Reply
  3. I just couldn’t go away your web site prior to suggesting
    that I really loved the standard info a person provide in your guests?
    Is gonna be back ceaselessly in order to check out new posts

    Reply
  4. I think this is one of the most vital info for me.

    And i’m glad reading your article. But want to remark on few general things, The web site style is great,
    the articles is really nice : D. Good job, cheers

    Reply

Leave a Comment