HTML and CSS Reference
In-Depth Information
Now, the results show “130” as expected when you add numbers. Whenever the plus ( + )
operator is used with text, it's called concatenation and simply strings everything together. If
you put any kind of text in a list of numbers to be added, and only one of the numbers is text,
all the rest will be treated as text and concatenated.
Different types of variables together
h e following program ( SimpleVariable.html in this chapter's folder at www.wiley.
com/go/smashinghtml5 ) uses all the dif erent kinds of data. You'll have to look closely at
the dif erent data types to determine the expected results. h e comments in the code should
help you see all the JavaScript data types.
<! DOCTYPE HTML >
< html >
< head >
< style type = ”text/css” >
/*BAD9CB,048C3F,7BA651,F2BE5C,F2A950 */
body {
background - color : #BAD9CB;
font - family : Verdana , Geneva , sans - serif ;
color : #048C3F;
}
</ style >
< script type = ”text/javascript” >
function advertisement ()
{
billVar = ”Brought to you by Bill's variable.” ;
return billVar ;
}
//Variable with function
popUpAd = advertisement ();
document . write ( popUpAd );
//Variable with HTML5 code
cr = ”<br>” ;
document . write ( cr );
// Variable with string
funHouse = ” Elm Street” ;
// Boolean variable
var fate =true;
// Variable with string
query = ”Will I find true happiness in HTML5? The answer is: “ ;
// Variables with numbers
fun = 100 ;
house = 23 ;
// Math with variables
funPlusHouse = fun + house ;
// Adding numeric and string variable (concatenation)
showAddress = funPlusHouse + funHouse ;
246
 
Search WWH ::




Custom Search