<< Chapter < Page Chapter >> Page >

PI times the square of the radius

The code in the function named getArea in Listing 4 computes the area and uses the assignment operator "=" to store the result in the variable named theArea . This statement represents a case where a value is being stored in a variable(assigned to the variable) for safekeeping.

Then the code in the function extracts the value stored in the variable named theArea and returns that value. After that, the function terminates and returns control to the place in the calling script from which itwas originally called.

The variable named area

Further down the page in Listing 4 , the script declares a variable named area without using the keyword var . (Note, however, that the keyword var could have been used here. I prefer that approach for reasons that I won't get into here.)

The script calls the getArea function, passing a radius value of 3.2 as a parameter. As you learned earlier, the value returned by thefunction replaces the call to the function, which is then assigned to the variable named area .

Display the results

Then the script calls the write method to display some text followed by the value stored in the variable named area , producing the output shown in Figure 8 in the browser window.

Figure 8 . Output from script in Listing 4 .
Area is: 32.169908772759484

The string concatenation operator

The code in Listing 4 exposes another operator that I will refer to as the string concatenation operator .

Note the argument list for the call to the write method in Listing 4 . In addition to being used to perform numeric addition, the plus operator "+" can be used to concatenate (join) two strings.

If two strings are joined by the + operator, the two strings will produce a new string that replaces the combination of the two originalstrings and the + operator.

If the left operand to the + operator is a string and the right operand is a numeric value (or the name of a variable containing a numeric value), thenumeric value will be replaced by a string of characters that represent that numeric value and the two strings will be concatenated into a single string.


The last item in the list under Structured programming is repetition , and that will be the topic of this section.

Repetition (also referred to as looping) means the act of causing something to repeat.

A repetition or loop is a set of commands that executes repeatedly until a specified condition is met.

JavaScript supports three loop statements:

  • while
  • for
  • do-while

The while loop

The while loop is not only the simplest of the three, it is also the most fundamental. It can be used to satisfy any requirement forrepetition in a JavaScript script. The other two exist solely for added convenience in some situations. Therefore, I will concentrate on the while loop, and leave the other two be be discussed in a future module, if at all.

Loop while a condition is true

A while loop executes the statements in its body for as long as a specified condition evaluates to true. The general syntax of a while loop is shown in Figure 9 .

Questions & Answers

how do I set up the problem?
Harshika Reply
what is a solution set?
find the subring of gaussian integers?
hello, I am happy to help!
Shirley Reply
please can go further on polynomials quadratic
hi mam
I need quadratic equation link to Alpa Beta
Abdullahi Reply
find the value of 2x=32
Felix Reply
divide by 2 on each side of the equal sign to solve for x
Want to review on complex number 1.What are complex number 2.How to solve complex number problems.
yes i wantt to review
use the y -intercept and slope to sketch the graph of the equation y=6x
Only Reply
how do we prove the quadratic formular
Seidu Reply
please help me prove quadratic formula
hello, if you have a question about Algebra 2. I may be able to help. I am an Algebra 2 Teacher
Shirley Reply
thank you help me with how to prove the quadratic equation
may God blessed u for that. Please I want u to help me in sets.
what is math number
Tric Reply
x-2y+3z=-3 2x-y+z=7 -x+3y-z=6
Sidiki Reply
can you teacch how to solve that🙏
Solve for the first variable in one of the equations, then substitute the result into the other equation. Point For: (6111,4111,−411)(6111,4111,-411) Equation Form: x=6111,y=4111,z=−411x=6111,y=4111,z=-411
x=61/11 y=41/11 z=−4/11 x=61/11 y=41/11 z=-4/11
Need help solving this problem (2/7)^-2
Simone Reply
what is the coefficient of -4×
Mehri Reply
the operation * is x * y =x + y/ 1+(x × y) show if the operation is commutative if x × y is not equal to -1
Alfred Reply
An investment account was opened with an initial deposit of $9,600 and earns 7.4% interest, compounded continuously. How much will the account be worth after 15 years?
Kala Reply
lim x to infinity e^1-e^-1/log(1+x)
given eccentricity and a point find the equiation
Moses Reply
A soccer field is a rectangle 130 meters wide and 110 meters long. The coach asks players to run from one corner to the other corner diagonally across. What is that distance, to the nearest tenths place.
Kimberly Reply
Jeannette has $5 and $10 bills in her wallet. The number of fives is three more than six times the number of tens. Let t represent the number of tens. Write an expression for the number of fives.
August Reply
What is the expressiin for seven less than four times the number of nickels
Leonardo Reply
How do i figure this problem out.
how do you translate this in Algebraic Expressions
linda Reply
why surface tension is zero at critical temperature
I think if critical temperature denote high temperature then a liquid stats boils that time the water stats to evaporate so some moles of h2o to up and due to high temp the bonding break they have low density so it can be a reason
Need to simplify the expresin. 3/7 (x+y)-1/7 (x-1)=
Crystal Reply
. After 3 months on a diet, Lisa had lost 12% of her original weight. She lost 21 pounds. What was Lisa's original weight?
Chris Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?

Megan Earhart
Start Quiz
Lakeima Roberts
Start Quiz