Hello @iguider10
First, for optimization do not repeat the same action again and again. Assign the result of the mathematical operation to a variable and use this variable in the comparisons:
(function(){
var v = fieldname1*699/100;
if(v < 1) return 0;
if(v < 199) return 'A1';
if(v < 299) return 'A2';
if(v < 399) return 'B1';
if(v < 499) return 'B2';
if(v < 599) return 'C1';
if(v < 699) return 'C2';
})()
Now, assuming you want to display this result in a text with the format: Hello, the result is …
If you want this text into the calculated field, the equation would be simply:
CONCATENATE(
'Hello, the result is ',
(function(){
var v = fieldname1*699/100;
if(v < 1) return 0;
if(v < 199) return 'A1';
if(v < 299) return 'A2';
if(v < 399) return 'B1';
if(v < 499) return 'B2';
if(v < 599) return 'C1';
if(v < 699) return 'C2';
})()
);
If you want to display the result into another field, like an “HTML Content” field. You can insert an “HTML Content” field in the form with content similar to:
Hello, the result is <span class="result-here"></span>
and then the equation would be similar to:
jQuery('.resul-here').html(
(function(){
var v = fieldname1*699/100;
if(v < 1) return 0;
if(v < 199) return 'A1';
if(v < 299) return 'A2';
if(v < 399) return 'B1';
if(v < 499) return 'B2';
if(v < 599) return 'C1';
if(v < 699) return 'C2';
})()
);
Best regards.
Thank you so much my friend, that works perfectly amazing ^^
Please last question, how can i show custom messages based on the result of a field ?
For exemple results of fieldname19 can be A1 or A2 or B1 or B2 or C1 or C2, so if a student has ‘A1’ it will be shown ‘Very BAD’… if he had C2 it will be shown ‘Perfect’ i tried this equation which i found on one of your topics but it didnt work for me
(function(){
if(fieldname19 = 'A1') return Very BAD;
if(fieldname19 = 'A2') return BAD;
if(fieldname19 = 'B1') return Need to work more;
if(fieldname19 = 'B2') return Well done;
if(fieldname19 = 'C1) return Good job;
if(fieldname19 = 'C2) return Perfect;
})()
See here i attached a picture on the page :https://preparationtcf.com/calculer-score-tv5-monde/
Sorry for my english and thank you so much again for your help, you so kind <3
Hello @iguider10
In javascript the texts’ values must be enclosed between single or double quotes. So, the equation would be:
(function(){
if(fieldname19 == 'A1') return 'Very BAD';
if(fieldname19 == 'A2') return 'BAD';
if(fieldname19 == 'B1') return 'Need to work more';
if(fieldname19 == 'B2') return 'Well done';
if(fieldname19 == 'C1) return 'Good job';
if(fieldname19 == 'C2) return 'Perfect';
})()
Best regards.
Sadly this code seems to not work with me :
(function(){
if(fieldname19 = 'A1') return 'Very BAD';
if(fieldname19 = 'A2') return 'BAD';
if(fieldname19 = 'B1') return 'Need to work more';
if(fieldname19 = 'B2') return 'Well done';
if(fieldname19 = 'C1') return 'Good job';
if(fieldname19 = 'C2') return 'Perfect';
})()
Feeling shy to ask you again, i did many ressearchs on other topics but did found the solution
Just for information, the fieldname19 is the result of a calculation here is the code :
jQuery('.result-here8').html(
(function(){
var v = fieldname17*699/80;
if(v < 1) return ;
if(v < 199) return 'A1';
if(v < 299) return 'A2';
if(v < 399) return 'B1';
if(v < 499) return 'B2';
if(v < 599) return 'C1';
if(v < 699) return 'C2';
})()
);
Means if for exemple the fieldname19 show B2 (after the calculation) i want in another field to show ‘Well done’
Thank you sir and sorry for the question :/
Hello @iguider10
The operator for equality is the double symbol: == because the symbol = is used for assignment:
(function(){
if(fieldname19 == 'A1') return 'Very BAD';
if(fieldname19 == 'A2') return 'BAD';
if(fieldname19 == 'B1') return 'Need to work more';
if(fieldname19 == 'B2') return 'Well done';
if(fieldname19 == 'C1) return 'Good job';
if(fieldname19 == 'C2) return 'Perfect';
})()
Best regards.
Amazing
It works like a charm ^_^
Thank you so much my friend for the help :* have a good day
Best wishes