简体   繁体   中英

Displaying converted string to number using console.log or document.write not working. Concatenation display not working not working either

I'm a beginner in JS and HTML and this program was for learning the concepts better. Trying out a basic program to convert a string to num in 3 ways. Unable to determine if the conversion has happened. Also unable to display concatenation of two such converted numbers.

The errors are thrown at lines consisting of console.log and document.write. Error:Uncaught Syntax Error: Illegal Character

What is the issue here?

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
      <h6>Q3</h6>
    <script type="text/javascript">
      numstr = "456";
      let num1 = numstr – 0;
      let num2 = parseInt(numstr);
      let num3 = new Number(numstr);
      console.log(typeof(num1));
      console.log(typeof(num2));
      console.log(typeof(num3));

    </script>
<br>
    <h6>Q4</h6>
    <script type="text/javascript">
        var num = 123.789;
        num2 = parseInt( num );
        num3 = parseInt( num, 8);
        console.log(num2 + “:::” + num3);
        document.write(num2 + “:::” + num3);
     </script>
  </body>
</html>

I think you copied and pasted it from some document. minus in let num1 = numstr – 0; is not a minus, but end dash symbol. Also replace quotes in “:::” into ":::"

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