Tham khảo sách 'javascript bible_ chapter 51', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Application Calculations and Graphics Perhaps because some of the first examples of applying JavaScript came from Netscape while the language was still called LiveScript the notion of creating HTML-based calculators has captured the imaginations of many page authors. Somewhere on the Web you can find probably every kind of special-purpose calculation normally done by scientific calculators and personal computer programs leaving only weather-modeling calculations to the Crays of the world. In the search for my calculator imprint on the JavaScript world I looked around for something more graphical. Numbers by themselves are pretty boring so any way the math could be enlivened was fine by me. Having been an electronics hobbyist since I was a kid I recalled the color coding of electronic resistor components. The values of these gizmos aren t printed in plain numbers anywhere. You have to know the code and the meaning of the location of the colored bands to arrive at the value of each one. I thought that this calculator would be fun to play with even if you don t know what a resistor is. The Calculation To give you an appreciation for the calculation that goes into determining a resistor s value here is the way the system works. Three closely spaced bands determine the resistance value in ohms. The first leftmost band is the tens digit the second middle band is the ones digit. Each color has a number from 0 through 9 assigned to it black 0 brown 1 and so on . Therefore if the first band is brown and the second band is black the number you start off with is 10. The third band is a multiplier. Each color determines the power of ten by which you multiply the first digits. For example the red color corresponds to a multiplier of 102 so 10 X 102 equals 1 000 ohms. In This Chapter Precached images Scripted tables CGI-like image assembly 54 JavaScript Applications A fourth band if present indicates the tolerance of the component how far plus or minus the resistance measurement