<< Chapter < Page Chapter >> Page >

Output for script in Listing 1

When you open the file in your browser, the text shown in Figure 1 should be displayed in the browser window.

Figure 1 . Output for script in Listing 1.
degrees = 90 : radians = 1.5707963267948965 radians = 1 : degrees = 57.29577951308232radians = 3.141592653589793 : degrees = 180

The toRadians and toDegrees functions

Because it will frequently be necessary for us to convert between degrees and radians, I decided to write two functions that we will use to make those conversions. Thatwill eliminate the need for us to stop and think about the conversion (and possibly get it backwards) when writingcode. We will simply call the function that performs the conversion in the required direction.

The toRadians function expects to receive an input parameter describing an angle in degreesand returns the value for that same angle in radians.

The toDegrees function expects to receive an input parameter describing an angle in radiansand returns the value for that same angle in degrees.

Global variables named degrees and radians

The code in Listing 1 begins by declaring global variables named degrees and radians . The variable named degrees is initialized to 90 degrees.

The toRadians function is called to convert that value of degrees to radians. The returned value in radians is stored in the variable named radians .

Display contents of both variables

Then the document.write method is called to display the values contained in both variables, producing the first line of output text shown in Figure 1 .

Modify variable contents, convert, and display again

Following that, a value of 1 is assigned to the variable named radians . The toDegrees function is called to convert that value to degrees, and the result is stored in the variable named degrees .

Once again, the document.write method is called to display the current contents of both variables, producing the second line of output textshown in Figure 1 .

One more time

Finally, the mathematical constant, PI, is stored in the variable named radians . Then that value is converted to degrees and stored in thevariable named degrees . The current values in both variables are displayed, producing the last line of output text shown in Figure1.

And the results were...

As you can see from Figure 1 ,

  • Ninety degrees is equal to 1.57 radians
  • One radian is equal to 57.296 degrees
  • 3.14 (PI) radians is equal to 180 degrees

A template

You might want to save your html file as a template for use with future exercises that require conversions between radians and degrees. This will beparticularly useful when we write scripts that use JavaScript's built-in trigonometric methods. Those methods deal with angles almost exclusively inradians while we tend to think of angles in degrees. We will use these two functions to perform conversions between degrees and radians whenrequired.

Sine, cosine, and tangent

An exercise involving a right triangle

For the next exercise, I would like for you to create a right triangle on your graph board by placing pushpins at the following coordinates:

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Accessible physics concepts for blind students. OpenStax CNX. Oct 02, 2015 Download for free at https://legacy.cnx.org/content/col11294/1.36
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?

Ask