Sair
  • Comunidade global
    • Idioma:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript &gt; and <

Envolvido ,
Jan 13, 2022 Jan 13, 2022

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

😉

1.6K
Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines

correct answers 1 resposta correta

Campeão , 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.

Traduzir
Campeão ,
Jan 13, 2022 Jan 13, 2022

Try putting parens around your statements like so...

 

if (num <= 20) {

 

else if (num >  95) {

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Orientador ,
Jan 13, 2022 Jan 13, 2022

Agree with @TLCMediaDesign 

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

 

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Envolvido ,
Jan 13, 2022 Jan 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... ???...

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Campeão ,
Jan 13, 2022 Jan 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.

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Envolvido ,
Jan 13, 2022 Jan 13, 2022

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

 

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Orientador ,
Jan 13, 2022 Jan 13, 2022

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.

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Envolvido ,
Jan 13, 2022 Jan 13, 2022

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

 

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Orientador ,
Jan 13, 2022 Jan 13, 2022

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);
}

 

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Campeão ,
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.

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Envolvido ,
Jan 13, 2022 Jan 13, 2022

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 !

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Envolvido ,
Jan 14, 2022 Jan 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...

...

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Orientador ,
Jan 14, 2022 Jan 14, 2022

Bon travail!

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Envolvido ,
Jan 14, 2022 Jan 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 !...

😉

...

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Orientador ,
Jan 14, 2022 Jan 14, 2022

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.

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Campeão ,
Jan 14, 2022 Jan 14, 2022

I always do it in an editor.

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines
Envolvido ,
Jan 14, 2022 Jan 14, 2022
MAIS RECENTE

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

Traduzir
Denunciar
Diretrizes da comunidade
Seja respeitoso, dê crédito à fonte original do conteúdo e verifique se há cópias antes da publicação. Saiba mais
community guidelines