Skip to main content
Dirlo
Inspiring
January 13, 2022
Answered

Javascript > and <

  • January 13, 2022
  • 3 replies
  • 1775 views

Hello !...

I want to create a "longest word game"... (Thanks to Greg's ressources...)

I manage to change the state of the letters without any problem...

But I try to give the letters a % of appearance... For example in french the voyel "E" appears far more often than the "Y" (which is a voyel in french !!)...

So that is for example my javascript for the choose of the voyel in % :

var num = Math.floor(Math.random() * 100) + 1;

if num <= 20 {
cp.changeState("SS_9_30_01","Lettre_"+1);  // corresponds to A
}

else if num > 20 && num <= 50 {
cp.changeState("SS_9_30_01","Lettre_"+2); // corresponds to E
}

else if num > 50 && num <= 70 {
cp.changeState("SS_9_30_01","Lettre_"+3); // corresponds to I
}

else if num > 70 && num <= 83 {
cp.changeState("SS_9_30_01","Lettre_"+4); // corresponds to O
}

else if num > 83 && num <= 95 {
cp.changeState("SS_9_30_01","Lettre_"+5); // corresponds to U
}

else if num >  95 {
cp.changeState("SS_9_30_01","Lettre_"+6); 
// corresponds to Y

}

 

But when I write or copy this code in the javascript action panel of Captivate, it changes my "<=" in this ": &lt;=" every time I try to save the code... which doesn't work obviously !...

 

So I need some help !... Thanks in advance !...

😉

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    It's in an Advanced Conditionnal Action...

    And it would be hard to add external JS file as I want to offer many choices (number of letters or time) in this project... so many JS options will be needed...

     


    Can you configure it to execute a simple action? It's when it is in an AA that those symbols cause issues.

    3 replies

    Dirlo
    DirloAuthor
    Inspiring
    January 14, 2022

    ...

    I just finished it !...

    And if I can judge by the time spent to publish it on my computer, it's one of the most ambitious project I've created so far !...

    I was about to come back here as I had problems with the countdown which I couldn't stop but I finally manage to deal with it, being very proud of myself on this matter !...

    The final project can be viewed here - in french, sorry ! - :

    https://soutien67.fr/francais/activites/Mot-le-plus-Long/Mot-le-plus-Long-01.htm

    Big thanks once again to both of you !...

    Happy Captivating !

    😉

    PS : I will also sent it to the e-learning community website...

    ...

    Stagprime2687219
    Brainiac
    January 14, 2022

    Bon travail!

    Dirlo
    DirloAuthor
    Inspiring
    January 14, 2022

    ...

    Thanks Greg !...

    I forgot to say that my eyes were burning after so many time on the action javascript panel !...

    As you hope, I believe the new Captivate software will help us !...

    😉

    ...

    Stagprime2687219
    Brainiac
    January 13, 2022

    Agree with @TLCMediaDesign 

    I have always had better success from placing the criteria to be evaluated in parentheses.

     

    Dirlo
    DirloAuthor
    Inspiring
    January 13, 2022

    Thanks for your help once again !...

    Unfortunately, it doesn't work for me...

    I try with () or even with []...

    Strangely the first < I use remains as expected... And there's no problem with the > symbol... ???...

    TLCMediaDesign
    Inspiring
    January 13, 2022

    Are you using the script in a simple JavaScript action or JavaScript in an Advanced Action?

     

    You may have to put your script in an external JS file and include it in the index page.

    TLCMediaDesign
    Inspiring
    January 13, 2022

    Try putting parens around your statements like so...

     

    if (num <= 20) {

     

    else if (num >  95) {