Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
664 views
in Technique[技术] by (71.8m points)

javascript - Argument type Number is not assignable to parameter type String|Function

var str = name.toUpperCase();
var ch = new Array();
ch = str.split('');

for(var i=0;i<7;i++)
{
  if(ch = null) {
    result_code.replace(
      pos.toString()+pos.toString()+pos.toString()+pos.toString(),
      "FFFF");
  } else {
    var temp = parseInt(ch[i]);
    var temp_integer = 64;
    if(temp<=122 & temp>=97) {
      var pos = i+1;
      result_code.replace(
        pos.toString()+pos.toString()+pos.toString()+pos.toString(),
        (temp - temp_integer)+40);
    }
  }
}

This code is creating the error at this line result_code.replace(pos.toString()+pos.toString()+pos.toString()+pos.toString(), (temp - temp_integer)+40);.

The underlined information is this section (temp - temp_integer)+40.

The error shown is Argument type Number is not assignable to parameter type String|Function.

What is wrong with this code? I am using WebStorm. I am likely just making a dumb mistake. Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The replace method accepts a string or a function as second parameter. Turn your value into a string: ((temp - temp_integer)+40).toString().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...