Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
656 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 Answer

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().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...