Chris
Chris

Reputation: 493

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!

Upvotes: 15

Views: 58649

Answers (2)

paxdiablo
paxdiablo

Reputation: 882028

(temp - temp_integer)+40

is a numeric value and replace wants a string. Just use:

(temp - temp_integer)+40+""

assuming that you want the string representation of the number (eg, 65 becomes "65"). If you want the character at that code point (65 becomes "A"), you should look into using String.fromCharCode().

Upvotes: 3

Guffa
Guffa

Reputation: 700562

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

Upvotes: 20

Related Questions