Resistor Color question!

Resistor Color question!

ni Saoud Alzoabi -
Number of replies: 16

I am trying to create a question in moodle where students get a random set of resistor colors to determine its value.

Example: 

1st = {black,brown,red,orange,yellow,green,blue,violet,gray,white};

2nd = {black,brown,red,orange,yellow,green,blue,violet,gray,white};

3rd = {black,brown,red,orange,yellow,green,blue};

4th = {red,gold,silver};

where students get a random set [1st - 2nd - 3rd - 4th].

Also I want to assign a weight for each color .. like black =0, brown = 1, .. etc


I tried several hours to come up with a solution, but I failed.

Average of ratings: -
In reply to Saoud Alzoabi

Re: Resistor Color question!

ni Dominique Bauer -
Larawan ng Documentation writers Larawan ng Particularly helpful Moodlers Larawan ng Plugin developers

Hello Saoud,

You can do this easily with the Formulas question and some JavaScript:


You can try it at https://moodleformulas.org/course/view.php?id=78&section=8 ↗.

Download the attached XML file and import it to try it out on your site.

In reply to Dominique Bauer

Re: Resistor Color question!

ni Saoud Alzoabi -
WOW this is great. Thank you so very much!! <3
I have tweaked your xml file and added more depth to the question by calculating the minimum and maximum value of a resistor.
Now, I wonder if I can reverse the question!! Like randomizing the value of a resistor and guess its colors. I did everything right, but it doesn't seem formula accepts a string as an answer malungkot
In reply to Saoud Alzoabi

Re: Resistor Color question!

ni Dominique Bauer -
Larawan ng Documentation writers Larawan ng Particularly helpful Moodlers Larawan ng Plugin developers
In reply to Dominique Bauer

Re: Resistor Color question!

ni Germán Valero -
Larawan ng Documentation writers Larawan ng Particularly helpful Moodlers Larawan ng Plugin developers Larawan ng Testers Larawan ng Translators
That (02 Resistor color codes) is a great question.
I wonder if that question could be translated into Spanish or French, particularly the names of the colors. I couldn't do it malungkot
In reply to Dominique Bauer

Re: Resistor Color question!

ni Saoud Alzoabi -
Hi Dominique, You saved my life!! <3
I made some tweaks on this question, and everything worked exactly the way I wanted.
Your help is so appreciated, and I wish you the best in every step you make.
In reply to Dominique Bauer

Re: Resistor Color question!

ni Germán Valero -
Larawan ng Documentation writers Larawan ng Particularly helpful Moodlers Larawan ng Plugin developers Larawan ng Testers Larawan ng Translators
That example is great, but maybe there should be an extra space between the third and fourth colors as seen in https://en.wikipedia.org/wiki/Electronic_color_code#Color_band_system

And I wonder why the first color rectangle looks taller than the others.
In reply to Germán Valero

Re: Resistor Color question!

ni Dominique Bauer -
Larawan ng Documentation writers Larawan ng Particularly helpful Moodlers Larawan ng Plugin developers
Hello Germán,

This is a 5 band resistor where the 5th band, for tolerance, is not displayed. The additional space is between the multiplier (4th band) and the tolerance (5th band, not shown).

The first band is very often shown larger because it is usually physically larger.

Best regards. ngiti
In reply to Dominique Bauer

Re: Resistor Color question!

ni Saoud Alzoabi -
I configured this question into 4 band resistor, and I added the tolerance to it.
Just one question though, If I want the student to write the color name instead of a drop down menu .. What should I write in the answer box? I am thinking {_0:color}, would that work?
In reply to Saoud Alzoabi

Re: Resistor Color question!

ni Dominique Bauer -
Larawan ng Documentation writers Larawan ng Particularly helpful Moodlers Larawan ng Plugin developers

Hello Saoud,

Unfortunately, the Formulas question does not include string answers. Surely this is something one would like to add to the question, but the development of this feature may take some time.

In the meantime, I propose a temporary solution using JavaScript. Obviously, this is just a workaround. The code may seem a bit long, but in reality it is very simple.

Here's what it looks like. Oops, sorry I did the example with a 5 band resistor. ngiti

You can try it at https://moodleformulas.org/course/view.php?id=78§ion=8 ↗

In reply to Dominique Bauer

Re: Resistor Color question!

ni Dominique Bauer -
Larawan ng Documentation writers Larawan ng Particularly helpful Moodlers Larawan ng Plugin developers
Hello Saoud and Germán,

I just realized that there is a small bug in example 2. The value 0 is not displayed for digit 1 (leading 0 not shown). Here is the fix and the new XML file.

I also realize that, as is, example 2 is not great. Indeed, the rank of colors in the drop-down lists corresponds to the digits, which gives away the answer. The colors should be shuffled in the dropdowns, which is feasible, but I think Example 3 is better anyway.

Formulas_20200914_0018.png


In reply to Dominique Bauer

Re: Resistor Color question!

ni Saoud Alzoabi -
Mr. Baur, I can't thank you enough!! You solved my problem completely!!
I tweaked your questions and I transferred it from 5 bands to 4 bands.

I am attaching both tweaked questions for those who are seeking 4 bands problems.