• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript &gt; and <

Engaged ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

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 !...

😉

Views

919

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Jan 13, 2022 Jan 13, 2022

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

Votes

Translate

Translate
People's Champ ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

Try putting parens around your statements like so...

 

if (num <= 20) {

 

else if (num >  95) {

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

Agree with @TLCMediaDesign 

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

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... ???...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

That is odd.

I admit I have never experienced what you describe myself using the JavaScript Window in Captivate.

I have done many projects using greater than and less than criteria.

This has my brain grinding gears at the moment.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

So I try to do it differently...

 

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

if (num == 1 || num == 2 || num == 3 ) {
cp.changeState("SS_9_30_01","Lettre_"+1);
}

else if (num == 4 || num == 5 || num == 6 || num == 7 ) {
cp.changeState("SS_9_30_01","Lettre_"+2);
}

else if (num == 8 || num == 9) {
cp.changeState("SS_9_30_01","Lettre_"+3);
}

else if (num == 10 || num == 11) {
cp.changeState("SS_9_30_01","Lettre_"+4);
}

else if (num == 12 || num == 13) {
cp.changeState("SS_9_30_01","Lettre_"+5);
}

else if num == 14 {
cp.changeState("SS_9_30_01","Lettre_"+6);
}

 

But this also doesn't work as expected... In fact the smartshape (SS_9_30_01) doesn't change... Maybe you could find what I done wrong in this code ?... (I try with | or with||)...

 

Edit : just find it !!!

I change the last line :

else if num == 14 {

to

else if (num == 14) {

And it seems to work as expected !...

Big thank you to both of you !... I will have to work the same with the consonnants now !...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

When using && or || I do it this way...

A few extra separations.

if ((num == 1) || (num == 2) || (num == 3 )) {
cp.changeState("SS_9_30_01","Lettre_"+1);
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

To Greg :

It's ok without the extra ()

And I use only one | instead of two || ???...

It works as well !!!...

To TLC :

I understood immediatly that it was the AA that causes the problem as I read your answer... (As Greg always use one JS action in his projects...)

But I'm not skilled enough in JS to do it by myself...

I will try my solution as it seems to work as I expected...

 

Big thanks again for your judicious advices !

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 14, 2022 Jan 14, 2022

Copy link to clipboard

Copied

...

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

...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 14, 2022 Jan 14, 2022

Copy link to clipboard

Copied

Bon travail!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 14, 2022 Jan 14, 2022

Copy link to clipboard

Copied

...

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 !...

😉

...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 14, 2022 Jan 14, 2022

Copy link to clipboard

Copied

When I have a project that is a bit more involved with the JavaScript - I will use a third party editor to write it all up and then paste it into the Captivate JavaScript editor.

I typically use Atom or Brackets with some type of monospaced font.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 14, 2022 Jan 14, 2022

Copy link to clipboard

Copied

I always do it in an editor.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 14, 2022 Jan 14, 2022

Copy link to clipboard

Copied

LATEST

Hopefully I have two screens... And Notepad ++ is my companion for the coding !... (I stop using the Js Cpt panel after 5 minutes...)

I don't know how this project would have been possible without their helps... And yours !...

Take care !... Big thanks again !...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources