How do I put backslash in strings in javascript?












0















So I'm making a cool terminal like 404 page for my fortnite stats site, I'm making so when you type a specific command it shows some ascii art, however whatever that's called is applying to the ascii art and removing a bunch of stuff like / so its just /. Is there any way to stop this from happening? Thanks.



    function showFortnite(){
$('.terminal').append("<div class='fortnite'>"+
"<p class='prompt'> ,---, </p>" +
"<p class='prompt'> ,`--.' | </p>" +
"<p class='prompt'> ,---,. ___ ___ | : : </p>" +
"<p class='prompt'> ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ; </p>" +
"<p class='prompt'>,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | | </p>" +
"<p class='prompt'>| | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ; </p>" +
"<p class='prompt'>: : : / / |' | |' |.;__,' / ,--.'|' |`--'_ .;__,' / ,---. | | ' </p>" +
"<p class='prompt'>: | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : | </p>" +
"<p class='prompt'>| : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ; </p>" +
"<p class='prompt'>| | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |`---'. | </p>" +
"<p class='prompt'>' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| `--..`; </p>" +
"<p class='prompt'>| | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_ </p>" +
"<p class='prompt'>| : `----' ---' | , / | |/ ; : ;| , / | : || |`. </p>" +
"<p class='prompt'>| | ,' ---`-' '---' | , / ---`-' / `-- -`, ; </p>" +
"<p class='prompt'>`----' ---`-' `----' '---` </p></div>");









share|improve this question





























    0















    So I'm making a cool terminal like 404 page for my fortnite stats site, I'm making so when you type a specific command it shows some ascii art, however whatever that's called is applying to the ascii art and removing a bunch of stuff like / so its just /. Is there any way to stop this from happening? Thanks.



        function showFortnite(){
    $('.terminal').append("<div class='fortnite'>"+
    "<p class='prompt'> ,---, </p>" +
    "<p class='prompt'> ,`--.' | </p>" +
    "<p class='prompt'> ,---,. ___ ___ | : : </p>" +
    "<p class='prompt'> ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ; </p>" +
    "<p class='prompt'>,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | | </p>" +
    "<p class='prompt'>| | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ; </p>" +
    "<p class='prompt'>: : : / / |' | |' |.;__,' / ,--.'|' |`--'_ .;__,' / ,---. | | ' </p>" +
    "<p class='prompt'>: | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : | </p>" +
    "<p class='prompt'>| : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ; </p>" +
    "<p class='prompt'>| | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |`---'. | </p>" +
    "<p class='prompt'>' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| `--..`; </p>" +
    "<p class='prompt'>| | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_ </p>" +
    "<p class='prompt'>| : `----' ---' | , / | |/ ; : ;| , / | : || |`. </p>" +
    "<p class='prompt'>| | ,' ---`-' '---' | , / ---`-' / `-- -`, ; </p>" +
    "<p class='prompt'>`----' ---`-' `----' '---` </p></div>");









    share|improve this question



























      0












      0








      0








      So I'm making a cool terminal like 404 page for my fortnite stats site, I'm making so when you type a specific command it shows some ascii art, however whatever that's called is applying to the ascii art and removing a bunch of stuff like / so its just /. Is there any way to stop this from happening? Thanks.



          function showFortnite(){
      $('.terminal').append("<div class='fortnite'>"+
      "<p class='prompt'> ,---, </p>" +
      "<p class='prompt'> ,`--.' | </p>" +
      "<p class='prompt'> ,---,. ___ ___ | : : </p>" +
      "<p class='prompt'> ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ; </p>" +
      "<p class='prompt'>,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | | </p>" +
      "<p class='prompt'>| | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ; </p>" +
      "<p class='prompt'>: : : / / |' | |' |.;__,' / ,--.'|' |`--'_ .;__,' / ,---. | | ' </p>" +
      "<p class='prompt'>: | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : | </p>" +
      "<p class='prompt'>| : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ; </p>" +
      "<p class='prompt'>| | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |`---'. | </p>" +
      "<p class='prompt'>' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| `--..`; </p>" +
      "<p class='prompt'>| | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_ </p>" +
      "<p class='prompt'>| : `----' ---' | , / | |/ ; : ;| , / | : || |`. </p>" +
      "<p class='prompt'>| | ,' ---`-' '---' | , / ---`-' / `-- -`, ; </p>" +
      "<p class='prompt'>`----' ---`-' `----' '---` </p></div>");









      share|improve this question
















      So I'm making a cool terminal like 404 page for my fortnite stats site, I'm making so when you type a specific command it shows some ascii art, however whatever that's called is applying to the ascii art and removing a bunch of stuff like / so its just /. Is there any way to stop this from happening? Thanks.



          function showFortnite(){
      $('.terminal').append("<div class='fortnite'>"+
      "<p class='prompt'> ,---, </p>" +
      "<p class='prompt'> ,`--.' | </p>" +
      "<p class='prompt'> ,---,. ___ ___ | : : </p>" +
      "<p class='prompt'> ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ; </p>" +
      "<p class='prompt'>,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | | </p>" +
      "<p class='prompt'>| | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ; </p>" +
      "<p class='prompt'>: : : / / |' | |' |.;__,' / ,--.'|' |`--'_ .;__,' / ,---. | | ' </p>" +
      "<p class='prompt'>: | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : | </p>" +
      "<p class='prompt'>| : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ; </p>" +
      "<p class='prompt'>| | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |`---'. | </p>" +
      "<p class='prompt'>' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| `--..`; </p>" +
      "<p class='prompt'>| | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_ </p>" +
      "<p class='prompt'>| : `----' ---' | , / | |/ ; : ;| , / | : || |`. </p>" +
      "<p class='prompt'>| | ,' ---`-' '---' | , / ---`-' / `-- -`, ; </p>" +
      "<p class='prompt'>`----' ---`-' `----' '---` </p></div>");






      javascript formatting markdown ascii-art






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 4:15









      Jacque Goupil

      2,9101736




      2,9101736










      asked Nov 22 '18 at 3:49









      BattleDashBattleDash

      508




      508
























          2 Answers
          2






          active

          oldest

          votes


















          2














          One option is to use String.raw, which will allow you to type single backslashes in a string without having to double-escape them. Normally, to use a literal backslash in a string, you need to escape it first, eg '\' is a string literal with a single backslash in it. But, String.raw allows you to type exactly what you want the string to be.



          The one issue is that String.raw's delimiters are backticks, which can only be escaped inside a template literal with a backslash before every backtick, so to keep the art aligned properly, replace all backticks with some other character, such as ~, while writing the art, and then replace all ~s with backticks afterwards.



          Also, use <pre>s with 0 margin to keep the alignment correct when displaying the text in the browser:






          const fortniteArt = String.raw`
          ,---,
          ,~--.' |
          ,---,. ___ ___ | : :
          ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ;
          ,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | |
          | | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ;
          : : : / / |' | |' |.;__,' / ,--.'|' |~--'_ .;__,' / ,---. | | '
          : | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : |
          | : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ;
          | | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |~---'. |
          ' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| ~--..~;
          | | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_
          | : ~----' ---' | , / | |/ ; : ;| , / | : || |~.
          | | ,' ---~-' '---' | , / ---~-' / ~-- -~, ;
          ~----' ---~-' ~----' '---~
          `;
          const htmlStr = "<div class='fortnite'>" + (
          fortniteArt
          .replace(/~/g, '`')
          .split('n')
          .slice(1) // remove first empty line, which is there for spacing reasons
          .map(line => `<pre class='prompt'>${line}</pre>`)
          .join('')
          ) + '</div>';
          $('.terminal').append(htmlStr);

          pre {
          margin: 0;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div class="terminal"></div>








          share|improve this answer


























          • Sorry for the late reply and thanks a lot lol, Is there any way to get a scroll effect on this? I'm not extremely good at javascript. My old code had this: $('.new-output').velocity( 'scroll' ), {duration: 100}

            – BattleDash
            Nov 22 '18 at 4:38











          • I don't know about .velocity, I was just answering the question posed, sorry

            – CertainPerformance
            Nov 22 '18 at 4:41











          • That's fine it doesn't really matter, Thanks for the help!

            – BattleDash
            Nov 22 '18 at 4:44



















          0














          Try to replace p with pre. Browser may leave whitespaces and special characters in pre as it is.






          share|improve this answer
























          • That just messed it up more, I figured out that if you do /\ it shows / Thanks!

            – BattleDash
            Nov 22 '18 at 4:04






          • 1





            While your intentions were good, you should probably test your solution to make sure it works before posting it. pre tags indeed help with whitespace but won't fix backslash escaping in JavaScript.

            – Jacque Goupil
            Nov 22 '18 at 4:12













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423609%2fhow-do-i-put-backslash-in-strings-in-javascript%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          One option is to use String.raw, which will allow you to type single backslashes in a string without having to double-escape them. Normally, to use a literal backslash in a string, you need to escape it first, eg '\' is a string literal with a single backslash in it. But, String.raw allows you to type exactly what you want the string to be.



          The one issue is that String.raw's delimiters are backticks, which can only be escaped inside a template literal with a backslash before every backtick, so to keep the art aligned properly, replace all backticks with some other character, such as ~, while writing the art, and then replace all ~s with backticks afterwards.



          Also, use <pre>s with 0 margin to keep the alignment correct when displaying the text in the browser:






          const fortniteArt = String.raw`
          ,---,
          ,~--.' |
          ,---,. ___ ___ | : :
          ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ;
          ,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | |
          | | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ;
          : : : / / |' | |' |.;__,' / ,--.'|' |~--'_ .;__,' / ,---. | | '
          : | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : |
          | : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ;
          | | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |~---'. |
          ' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| ~--..~;
          | | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_
          | : ~----' ---' | , / | |/ ; : ;| , / | : || |~.
          | | ,' ---~-' '---' | , / ---~-' / ~-- -~, ;
          ~----' ---~-' ~----' '---~
          `;
          const htmlStr = "<div class='fortnite'>" + (
          fortniteArt
          .replace(/~/g, '`')
          .split('n')
          .slice(1) // remove first empty line, which is there for spacing reasons
          .map(line => `<pre class='prompt'>${line}</pre>`)
          .join('')
          ) + '</div>';
          $('.terminal').append(htmlStr);

          pre {
          margin: 0;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div class="terminal"></div>








          share|improve this answer


























          • Sorry for the late reply and thanks a lot lol, Is there any way to get a scroll effect on this? I'm not extremely good at javascript. My old code had this: $('.new-output').velocity( 'scroll' ), {duration: 100}

            – BattleDash
            Nov 22 '18 at 4:38











          • I don't know about .velocity, I was just answering the question posed, sorry

            – CertainPerformance
            Nov 22 '18 at 4:41











          • That's fine it doesn't really matter, Thanks for the help!

            – BattleDash
            Nov 22 '18 at 4:44
















          2














          One option is to use String.raw, which will allow you to type single backslashes in a string without having to double-escape them. Normally, to use a literal backslash in a string, you need to escape it first, eg '\' is a string literal with a single backslash in it. But, String.raw allows you to type exactly what you want the string to be.



          The one issue is that String.raw's delimiters are backticks, which can only be escaped inside a template literal with a backslash before every backtick, so to keep the art aligned properly, replace all backticks with some other character, such as ~, while writing the art, and then replace all ~s with backticks afterwards.



          Also, use <pre>s with 0 margin to keep the alignment correct when displaying the text in the browser:






          const fortniteArt = String.raw`
          ,---,
          ,~--.' |
          ,---,. ___ ___ | : :
          ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ;
          ,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | |
          | | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ;
          : : : / / |' | |' |.;__,' / ,--.'|' |~--'_ .;__,' / ,---. | | '
          : | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : |
          | : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ;
          | | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |~---'. |
          ' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| ~--..~;
          | | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_
          | : ~----' ---' | , / | |/ ; : ;| , / | : || |~.
          | | ,' ---~-' '---' | , / ---~-' / ~-- -~, ;
          ~----' ---~-' ~----' '---~
          `;
          const htmlStr = "<div class='fortnite'>" + (
          fortniteArt
          .replace(/~/g, '`')
          .split('n')
          .slice(1) // remove first empty line, which is there for spacing reasons
          .map(line => `<pre class='prompt'>${line}</pre>`)
          .join('')
          ) + '</div>';
          $('.terminal').append(htmlStr);

          pre {
          margin: 0;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div class="terminal"></div>








          share|improve this answer


























          • Sorry for the late reply and thanks a lot lol, Is there any way to get a scroll effect on this? I'm not extremely good at javascript. My old code had this: $('.new-output').velocity( 'scroll' ), {duration: 100}

            – BattleDash
            Nov 22 '18 at 4:38











          • I don't know about .velocity, I was just answering the question posed, sorry

            – CertainPerformance
            Nov 22 '18 at 4:41











          • That's fine it doesn't really matter, Thanks for the help!

            – BattleDash
            Nov 22 '18 at 4:44














          2












          2








          2







          One option is to use String.raw, which will allow you to type single backslashes in a string without having to double-escape them. Normally, to use a literal backslash in a string, you need to escape it first, eg '\' is a string literal with a single backslash in it. But, String.raw allows you to type exactly what you want the string to be.



          The one issue is that String.raw's delimiters are backticks, which can only be escaped inside a template literal with a backslash before every backtick, so to keep the art aligned properly, replace all backticks with some other character, such as ~, while writing the art, and then replace all ~s with backticks afterwards.



          Also, use <pre>s with 0 margin to keep the alignment correct when displaying the text in the browser:






          const fortniteArt = String.raw`
          ,---,
          ,~--.' |
          ,---,. ___ ___ | : :
          ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ;
          ,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | |
          | | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ;
          : : : / / |' | |' |.;__,' / ,--.'|' |~--'_ .;__,' / ,---. | | '
          : | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : |
          | : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ;
          | | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |~---'. |
          ' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| ~--..~;
          | | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_
          | : ~----' ---' | , / | |/ ; : ;| , / | : || |~.
          | | ,' ---~-' '---' | , / ---~-' / ~-- -~, ;
          ~----' ---~-' ~----' '---~
          `;
          const htmlStr = "<div class='fortnite'>" + (
          fortniteArt
          .replace(/~/g, '`')
          .split('n')
          .slice(1) // remove first empty line, which is there for spacing reasons
          .map(line => `<pre class='prompt'>${line}</pre>`)
          .join('')
          ) + '</div>';
          $('.terminal').append(htmlStr);

          pre {
          margin: 0;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div class="terminal"></div>








          share|improve this answer















          One option is to use String.raw, which will allow you to type single backslashes in a string without having to double-escape them. Normally, to use a literal backslash in a string, you need to escape it first, eg '\' is a string literal with a single backslash in it. But, String.raw allows you to type exactly what you want the string to be.



          The one issue is that String.raw's delimiters are backticks, which can only be escaped inside a template literal with a backslash before every backtick, so to keep the art aligned properly, replace all backticks with some other character, such as ~, while writing the art, and then replace all ~s with backticks afterwards.



          Also, use <pre>s with 0 margin to keep the alignment correct when displaying the text in the browser:






          const fortniteArt = String.raw`
          ,---,
          ,~--.' |
          ,---,. ___ ___ | : :
          ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ;
          ,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | |
          | | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ;
          : : : / / |' | |' |.;__,' / ,--.'|' |~--'_ .;__,' / ,---. | | '
          : | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : |
          | : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ;
          | | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |~---'. |
          ' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| ~--..~;
          | | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_
          | : ~----' ---' | , / | |/ ; : ;| , / | : || |~.
          | | ,' ---~-' '---' | , / ---~-' / ~-- -~, ;
          ~----' ---~-' ~----' '---~
          `;
          const htmlStr = "<div class='fortnite'>" + (
          fortniteArt
          .replace(/~/g, '`')
          .split('n')
          .slice(1) // remove first empty line, which is there for spacing reasons
          .map(line => `<pre class='prompt'>${line}</pre>`)
          .join('')
          ) + '</div>';
          $('.terminal').append(htmlStr);

          pre {
          margin: 0;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div class="terminal"></div>








          const fortniteArt = String.raw`
          ,---,
          ,~--.' |
          ,---,. ___ ___ | : :
          ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ;
          ,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | |
          | | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ;
          : : : / / |' | |' |.;__,' / ,--.'|' |~--'_ .;__,' / ,---. | | '
          : | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : |
          | : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ;
          | | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |~---'. |
          ' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| ~--..~;
          | | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_
          | : ~----' ---' | , / | |/ ; : ;| , / | : || |~.
          | | ,' ---~-' '---' | , / ---~-' / ~-- -~, ;
          ~----' ---~-' ~----' '---~
          `;
          const htmlStr = "<div class='fortnite'>" + (
          fortniteArt
          .replace(/~/g, '`')
          .split('n')
          .slice(1) // remove first empty line, which is there for spacing reasons
          .map(line => `<pre class='prompt'>${line}</pre>`)
          .join('')
          ) + '</div>';
          $('.terminal').append(htmlStr);

          pre {
          margin: 0;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div class="terminal"></div>





          const fortniteArt = String.raw`
          ,---,
          ,~--.' |
          ,---,. ___ ___ | : :
          ,' .' | ,--.'|_ ,--, ,--.'|_ ' ' ;
          ,---.' | ,---. __ ,-. | | :,' ,---, ,--.'| | | :,' | | |
          | | .' ' ,' ,' ,'/ /| : : ' : ,-+-. / || |, : : ' : ' : ;
          : : : / / |' | |' |.;__,' / ,--.'|' |~--'_ .;__,' / ,---. | | '
          : | |-,. ; ,. :| | ,'| | | | | ,' |,' ,'| | | | / ' : |
          | : ;/|' | |: :' : / :__,'| : | | / | |' | | :__,'| : / / |; | ;
          | | .'' | .; :| | ' ' : |__ | | | | || | : ' : |__ . ' / |~---'. |
          ' : ' | : |; : | | | '.'|| | | |/ ' : |__ | | '.'|' ; /| ~--..~;
          | | | / | , ; ; : ;| | |--' | | '.'|; : ;' | / |.--,_
          | : ~----' ---' | , / | |/ ; : ;| , / | : || |~.
          | | ,' ---~-' '---' | , / ---~-' / ~-- -~, ;
          ~----' ---~-' ~----' '---~
          `;
          const htmlStr = "<div class='fortnite'>" + (
          fortniteArt
          .replace(/~/g, '`')
          .split('n')
          .slice(1) // remove first empty line, which is there for spacing reasons
          .map(line => `<pre class='prompt'>${line}</pre>`)
          .join('')
          ) + '</div>';
          $('.terminal').append(htmlStr);

          pre {
          margin: 0;
          }

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          <div class="terminal"></div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 4:11

























          answered Nov 22 '18 at 4:06









          CertainPerformanceCertainPerformance

          80.4k143865




          80.4k143865













          • Sorry for the late reply and thanks a lot lol, Is there any way to get a scroll effect on this? I'm not extremely good at javascript. My old code had this: $('.new-output').velocity( 'scroll' ), {duration: 100}

            – BattleDash
            Nov 22 '18 at 4:38











          • I don't know about .velocity, I was just answering the question posed, sorry

            – CertainPerformance
            Nov 22 '18 at 4:41











          • That's fine it doesn't really matter, Thanks for the help!

            – BattleDash
            Nov 22 '18 at 4:44



















          • Sorry for the late reply and thanks a lot lol, Is there any way to get a scroll effect on this? I'm not extremely good at javascript. My old code had this: $('.new-output').velocity( 'scroll' ), {duration: 100}

            – BattleDash
            Nov 22 '18 at 4:38











          • I don't know about .velocity, I was just answering the question posed, sorry

            – CertainPerformance
            Nov 22 '18 at 4:41











          • That's fine it doesn't really matter, Thanks for the help!

            – BattleDash
            Nov 22 '18 at 4:44

















          Sorry for the late reply and thanks a lot lol, Is there any way to get a scroll effect on this? I'm not extremely good at javascript. My old code had this: $('.new-output').velocity( 'scroll' ), {duration: 100}

          – BattleDash
          Nov 22 '18 at 4:38





          Sorry for the late reply and thanks a lot lol, Is there any way to get a scroll effect on this? I'm not extremely good at javascript. My old code had this: $('.new-output').velocity( 'scroll' ), {duration: 100}

          – BattleDash
          Nov 22 '18 at 4:38













          I don't know about .velocity, I was just answering the question posed, sorry

          – CertainPerformance
          Nov 22 '18 at 4:41





          I don't know about .velocity, I was just answering the question posed, sorry

          – CertainPerformance
          Nov 22 '18 at 4:41













          That's fine it doesn't really matter, Thanks for the help!

          – BattleDash
          Nov 22 '18 at 4:44





          That's fine it doesn't really matter, Thanks for the help!

          – BattleDash
          Nov 22 '18 at 4:44













          0














          Try to replace p with pre. Browser may leave whitespaces and special characters in pre as it is.






          share|improve this answer
























          • That just messed it up more, I figured out that if you do /\ it shows / Thanks!

            – BattleDash
            Nov 22 '18 at 4:04






          • 1





            While your intentions were good, you should probably test your solution to make sure it works before posting it. pre tags indeed help with whitespace but won't fix backslash escaping in JavaScript.

            – Jacque Goupil
            Nov 22 '18 at 4:12


















          0














          Try to replace p with pre. Browser may leave whitespaces and special characters in pre as it is.






          share|improve this answer
























          • That just messed it up more, I figured out that if you do /\ it shows / Thanks!

            – BattleDash
            Nov 22 '18 at 4:04






          • 1





            While your intentions were good, you should probably test your solution to make sure it works before posting it. pre tags indeed help with whitespace but won't fix backslash escaping in JavaScript.

            – Jacque Goupil
            Nov 22 '18 at 4:12
















          0












          0








          0







          Try to replace p with pre. Browser may leave whitespaces and special characters in pre as it is.






          share|improve this answer













          Try to replace p with pre. Browser may leave whitespaces and special characters in pre as it is.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 3:55









          below-1below-1

          3113




          3113













          • That just messed it up more, I figured out that if you do /\ it shows / Thanks!

            – BattleDash
            Nov 22 '18 at 4:04






          • 1





            While your intentions were good, you should probably test your solution to make sure it works before posting it. pre tags indeed help with whitespace but won't fix backslash escaping in JavaScript.

            – Jacque Goupil
            Nov 22 '18 at 4:12





















          • That just messed it up more, I figured out that if you do /\ it shows / Thanks!

            – BattleDash
            Nov 22 '18 at 4:04






          • 1





            While your intentions were good, you should probably test your solution to make sure it works before posting it. pre tags indeed help with whitespace but won't fix backslash escaping in JavaScript.

            – Jacque Goupil
            Nov 22 '18 at 4:12



















          That just messed it up more, I figured out that if you do /\ it shows / Thanks!

          – BattleDash
          Nov 22 '18 at 4:04





          That just messed it up more, I figured out that if you do /\ it shows / Thanks!

          – BattleDash
          Nov 22 '18 at 4:04




          1




          1





          While your intentions were good, you should probably test your solution to make sure it works before posting it. pre tags indeed help with whitespace but won't fix backslash escaping in JavaScript.

          – Jacque Goupil
          Nov 22 '18 at 4:12







          While your intentions were good, you should probably test your solution to make sure it works before posting it. pre tags indeed help with whitespace but won't fix backslash escaping in JavaScript.

          – Jacque Goupil
          Nov 22 '18 at 4:12




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423609%2fhow-do-i-put-backslash-in-strings-in-javascript%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen