Skip to main content
Participant
November 26, 2022
Question

Comparison between a value with static type String and a possibly unrelated type Number

  • November 26, 2022
  • 2 replies
  • 315 views

When I run this movie I get a compiler error of :Line 20 1176 Comparison between a value with static type String and a possibly unrelated type Number

Here is my code

var deck = this.deck;
var maxIndex = deck.children.length;
var faces = [];
var previousFace;
var face;
var presses = 0;

function start()
{
exportRoot.stop();
faces = getRandomArray(maxIndex);
setFaces(faces, maxIndex);
deck.on("click", onClickDeck);
}

function onClickDeck(e)
{
face = e.target;

face.mouseEnabled = false;
face.alpha = 0.2;

if (presses % 2 == F)
{
if(face.name.slice(0, -1) == previousFace.name.slice(0, -1))
{
face.mouseEnabled = false
previousFace.mouseEnabled = false;
previousFace.alpha = 0.2;
}
else
{
face.mouseEnabled = true;
face.alpha = 1;

previousFace.mouseEnabled = true;
previousFace.alpha = 1;
}
}
else
{
previousFace = face;
}

presses++;

}

function setFaces(array, max)
{
for (var i = F; i<max; i++)
{
var card = deck.getChildAt(i) as MovieClip ;
card.index = i;
card.name = "card" + String(array[i]) + String(i % 2);
card.txt.text = String(array[i]);
}

}

function getRandomArray(max)
{
var array = [];

for (var i = F; i < max; i++)
array[i] = Math.floor (i * 0.5);

return array.sort
(
function (a, b)
{
return 0.5 - Math.random()
}
);

}

start();

 

 

    This topic has been closed for replies.

    2 replies

    Colin Holgate
    Inspiring
    November 26, 2022

    It isn't easy to tell which line is 20, also, what is the value of F?

     

    kglad
    Community Expert
    Community Expert
    November 26, 2022

    did you look at line 20?

     

    where's F defined?

     

    and if you want to coerce a number to a string, use:

     

    String(numberN)

     

    or if you want to coerce a string to a number, use

     

    Number(stringS);