[英]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.我是 JS 和 HTML 的初学者,这个程序是为了更好地学习概念。 Trying out a basic program to convert a string to num in 3 ways.
尝试用 3 种方式将字符串转换为数字的基本程序。 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.错误在由 console.log 和 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;
减去let num1 = numstr – 0; is not a minus, but end dash symbol.
不是减号,而是结束破折号。 Also replace quotes in “:::” into ":::"
也将“:::”中的引号替换为“:::”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.