<?xml version="1.0" encoding="UTF-8"?>
<eventos>
<topico>
<nome>Exemplos de funções no Javascript</nome>
<titulo>Exemplos de funções no Javascript</titulo>
<descritor>Exemplos de funções no Javascript&lt;br&gt;
</descritor>
<lead>Exemplos para manipular funções &lt;span style=&quot;font-weight: bold;&quot;&gt;internamente&lt;/span&gt; ao html. Tipos de
manipulação: sem função, com função, mais de uma função, funções
aninhadas dentro de outras funções. Exemplo para manipular funções &lt;span style=&quot;font-weight: bold;&quot;&gt;externamente&lt;/span&gt; ao html.
</lead>
<link>link</link>
<origem>WExemplosFuncoesJavascript.xml</origem>
<referencia>referencia</referencia>
</topico>
<topico>
<titulo>Exemplo 1 - Executando o js embutido
na tag &amp;lt;html&amp;gt;&amp;nbsp; - Inline&lt;br&gt;
</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;escrever um script em
javascript para escrever&lt;span style=&quot;font-weight: bold;&quot;&gt; olá&lt;/span&gt; em
um documento html &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;carregando primeiro a pagina e depois
o javascript e &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;escrevendo de 2 modos diferentes: &lt;br&gt;
a- no proprio browse &lt;br&gt;
b- em uma janela de alerta.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;br&gt;
Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;br&gt;
&amp;lt;!-- versao 1 do pgm &lt;span style=&quot;font-weight: bold;&quot;&gt;ola&lt;/span&gt;--&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &lt;br&gt;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;&lt;br&gt;
&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot;
lang=&quot;en&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;head&amp;gt;&lt;br&gt;
&amp;lt;title&amp;gt;pgm para escrever olá no documento html&amp;lt;/title&amp;gt;&lt;br&gt;
&amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;
/&amp;gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
pgm para escrever &lt;span style=&quot;font-weight: bold;&quot;&gt;olá &lt;/span&gt;no
documento html: &amp;lt;br&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;script language=&quot;JavaScript&quot;&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;// avisa que a
partir daqui vai usar script em javascript&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;/*a*/&amp;nbsp;
document.write(&quot;olá
&quot;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp;
Escrever no documento html e mostrar no browse&lt;br&gt;
/*b*/&amp;nbsp; alert (&quot;ola&quot;); &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
//&amp;nbsp;&amp;nbsp; Mostrar a mensagem&amp;nbsp; atraves de uma janela de alerta
do&amp;nbsp; browse &lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/html&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs.:&lt;/span&gt;&lt;br&gt;
1. Copiar codigo acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
2. O codigo após testado será salvo em biblioteca de paginas como
ola.html&lt;br&gt;
3. A função javascript pode estar embutido na tag &amp;lt;head&amp;gt; ou na
tag &amp;lt;body&amp;gt;. Por uma questão de performace o melhor posicionamento
é na tag &amp;lt;body&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Legenda:&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;vermelho&lt;/span&gt;
--&amp;gt; codigo em html &lt;br&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;azul&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
--&amp;gt; codigo em
javascript </desc>
<topico>
<titulo>Exemplo 2 - Declarando e invovando uma
função embutida no html &lt;br&gt;
</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Escrever um script em
javascript para escrever&lt;span style=&quot;font-weight: bold;&quot;&gt; olá&lt;/span&gt; em
um documento html &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;carregando primeiro a pagina e depois
o javascript e &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;escrevendo de 2 modos diferentes: &lt;br&gt;
a- no proprio browse &lt;br&gt;
b- em uma janela de alerta.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;O codigo da função deverá ficar num
arquivo externo do html&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;A invocação da função deverá ser
feita embutida ao html.&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;br&gt;
Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;!-- versao 2 do pgm &lt;span style=&quot;font-weight: bold;&quot;&gt;ola&lt;/span&gt;--&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;!DOCTYPE html
PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &lt;br&gt;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;&lt;br&gt;
&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot;
lang=&quot;en&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;head&amp;gt;&lt;br&gt;
&amp;lt;title&amp;gt;pgm para escrever olá no documento html&amp;lt;/title&amp;gt;&lt;br&gt;
&amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;
/&amp;gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
pgm para escrever olá no documento html: &amp;lt;br&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;script language=&quot;JavaScript&quot;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;&amp;nbsp; // avisa que a
partir daqui vai usar script em javascript&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;
&amp;nbsp;
&lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;function escreve( ) {&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;/*a*/&amp;nbsp;
document.write(&quot;olá &quot;); &amp;nbsp; &amp;nbsp; //&amp;nbsp; Escreve olá no documento
html e mostra no browse&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;/*b*/&amp;nbsp; alert
(&quot;ola&quot;);&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp; //&amp;nbsp; Escreve olá no documento html e mostra em
uma janela do&amp;nbsp; browse&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;}&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;&amp;nbsp; escreve(
);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //
invoca a função escreve&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/html&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs.:&lt;/span&gt;&lt;br&gt;
1. Copiar codigo acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
2. O codigo após testado será salvo em biblioteca de paginas como
ola2.html&lt;br&gt;
3. A função javascript pode estar embutido na tag &amp;lt;head&amp;gt; ou na
tag &amp;lt;body&amp;gt;. Por uma questão de performace o melhor posicionamento
é na tag &amp;lt;body&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Legenda:&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;vermelho&lt;/span&gt;
--&amp;gt; codigo em html &lt;br&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;azul&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
--&amp;gt; codigo em
javascript </desc>
</topico>
ieldset&amp;gt;</topico>
<topico>
<titulo>Exemplo 3 Invocando com uma função
externa ao html, como arquivo .js &lt;br&gt;
</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Escrever um script em
javascript para escrever&lt;span style=&quot;font-weight: bold;&quot;&gt; olá&lt;/span&gt; em
um documento html &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;carregando primeiro a pagina e depois
o javascript e &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;escrevendo de 2 modos diferentes: &lt;br&gt;
a- no proprio browse &lt;br&gt;
b- em uma janela de alerta.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;O codigo da função deverá ficar num
arquivo externo do html&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;A invocação da função deverá ser
feita embutida ao htm&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;br&gt;
Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;!--
versao 3 do pgm &lt;span style=&quot;font-weight: bold;&quot;&gt;ola&lt;/span&gt;--&amp;gt;&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;!DOCTYPE
html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &lt;br&gt;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;&lt;br&gt;
&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot;
lang=&quot;en&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;head&amp;gt;&lt;br&gt;
&amp;lt;title&amp;gt;pgm para escrever olá no documento html&amp;lt;/title&amp;gt;&lt;br&gt;
&amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;
/&amp;gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
pgm para escrever olá no documento html: &amp;lt;br&amp;gt;&lt;/span&gt; &lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;A data e hora
corrente é:&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;script
language=&quot;JavaScript&quot; src=&quot;ola3.js &amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;// posicionamento
recomendado&lt;br&gt;
&lt;br&gt;escreve(
);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
// chama a função escreve que esta descrita em ola2.js&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs.:&lt;/span&gt;&lt;br&gt;
1. &lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;arquivo ola2.js&lt;/span&gt;&lt;br&gt;
function escreve( ) {&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;/*a*/&amp;nbsp;
document.write(&quot;olá &quot;); &amp;nbsp; &amp;nbsp; //&amp;nbsp; Escreve olá no documento
html e mostra no browse&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;/*b*/&amp;nbsp; alert
(&quot;ola&quot;);&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp; //&amp;nbsp; Escreve olá no documento html e mostra em
uma janela do&amp;nbsp; browse&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
Copiar codigo da função acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Legenda:&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;vermelho&lt;/span&gt;
--&amp;gt; codigo em html &lt;br&gt;
&lt;span style=&quot;background-color: rgb(51, 204, 255);&quot;&gt;azul&amp;nbsp;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
--&amp;gt; codigo em
javascript
</desc>
</topico>
<topico>
<titulo>Exemplo 4 Executando várias funções
sequencialmente&lt;br&gt;
</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Executar varias funcões
sequencialmente e &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;e executar no browser e mostrar em
uma pagina html&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt; O codigo &lt;br&gt;
&lt;br&gt;
Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;br&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;title&amp;gt;pgm executa varias
funções &amp;lt;/title&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script
language=&quot;JavaScript&quot;&amp;gt;&amp;nbsp; // abre script javascript&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;// FUNÇÃO 1 Mostra uma mensagem,
sem document.write()&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;// Não retorna nenhum valor&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br&gt;
function imprimir(msg)&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
document.write(msg, &quot;&amp;lt;br&amp;gt;&quot;);&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;// FUNÇÃO 2 Calcula e retorna a
distancia entre 2 pontos&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br&gt;
function distancia(x1, y1, x2, y2)&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var dx = x2 -
x1;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var dy = y2 -
y1;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return
Math.sqrt(dx*dx + dy*dy);&amp;nbsp; // função nativa do javascript&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;// FUNÇÃO 3 Recursiva (chama ela
mesmo) e retorna um valor&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;// Calcula fatorial de x ou seja
é produto de x&amp;nbsp; e todos&amp;nbsp; inteiros positivos menores que ele.
Ex 3! = 3 x 2 x 1.&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br&gt;
function fatorial(x)&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (x &amp;lt;= 1)&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
return 1;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x *
factorial(x-1);&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;/script&amp;gt;&amp;nbsp;&amp;nbsp; &amp;lt;!...&amp;nbsp; fecha script&amp;nbsp; ....&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;script
language=&quot;JavaScript&quot;&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;// executa as funções definidas
no head na ordem em que é chamada&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; imprimir (&quot;Hello&quot; );&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; nome = &quot; Joao&quot;;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; imprimir(&quot;Benvindo a
minha pagina &quot; + nome);&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; total_dist = distancia
(0,0,2,1) + distancia (2,1,3,5);&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; imprimir (&quot;Distancia
total =&quot; + total_dist);&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; imprimir(&quot;fatorial de 3
é: &quot;+ fatorial (3));&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; imprimir(&quot;A probabilidade
disto é:&quot;+ fatorial (39)/fatorial(52));&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 1.:&lt;/span&gt;&lt;br&gt;
Copiar codigo acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs2.:&lt;/span&gt;&lt;br&gt;
A função&amp;nbsp; imprimir( ) não contem uma instrução return, assim ela
sempre retorna o valor undefined e não pode ser usada como parte de uma
expressão maior. As funções distancia( ) e fatorial( ), por outro lado,
podem ser chamadas como partes de expressões maiores como vist acima.&lt;br&gt;
</desc>
</topico>
<topico>
<titulo>Exemplo 4 Executando funções aninhadas
dentro de outras&lt;br&gt;
</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Executar varias funcões
aninhadas dentro de outras &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;executar no browser e mostrar em uma
pagina html&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;br&gt;
Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;title&amp;gt;pgm aninha varias
funções &amp;lt;/title&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script
language=&quot;JavaScript&quot;&amp;gt;&amp;nbsp; // abre script javascript&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;// FUNÇÃO calcula a hipotenusa A
soma dos quadrados dos catetos é igual ao quadrado da hipotenusa&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;// hipotenusa&amp;nbsp; = raiz
quadrada (cateto (a)² + cateto (b)² )&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;function hipotenusa (a, b) {&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; function square (x)
{return x*x}&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; return
Math.sqrt(square(a) + square (b));&amp;nbsp; // Math - objeto intrinsico ao
nucleo do js. sqrt - raiz quadrada&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;lt;/script&amp;gt;&amp;nbsp;&amp;nbsp; &amp;lt;!...&amp;nbsp; fecha script&amp;nbsp; ....&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;script
language=&quot;JavaScript&quot;&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;// executa a função definidas no
head &lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;
document.write(&quot;hipotenusa = &quot; + hipotenusa (2, 3) ); &lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 1.:&lt;/span&gt;&lt;br&gt;
Copiar codigo acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 2:&lt;/span&gt;&lt;br&gt;
A declaração function não pode aparecer dentro de laços ou condições
(if). Já os literais de função podem.&lt;br&gt;
</desc>
</topico>
<topico>
<titulo>Exemplo n1 - Executando sem função,
incluindo direto no html</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Obter&amp;nbsp; data e hora
corrente interna do computador &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;e executar o javascript no browser e
mostrar em uma pagina html&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;br&gt;
Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;!-- versao 2 do pgm &lt;span style=&quot;font-weight: bold;&quot;&gt;ola&lt;/span&gt;--&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;title&amp;gt;pgm
para imprimir data e hora corrente&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;A data e hora
corrente é:&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;script
language=&quot;JavaScript&quot;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;&amp;nbsp; // avisa que a
partir daqui vai usar script em javascript&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;var data = new
Date();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
// Obter data and hora corrente&lt;/span&gt;&lt;br style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;
&lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;
&amp;nbsp; document.write(data.toLocaleString());&amp;nbsp; //&amp;nbsp; Inserir no
documento&amp;nbsp; no documento html e mostrar no browse &lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;br style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&amp;lt;/html&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs.:&lt;/span&gt;&lt;br&gt;
1. Copiar codigo acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
2. O codigo após testado será salvo em biblioteca de paginas como
ola1.html&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Legenda:&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;vermelho&lt;/span&gt;
--&amp;gt; codigo em html &lt;br&gt;
&lt;span style=&quot;background-color: rgb(51, 102, 255);&quot;&gt;azul&amp;nbsp;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
--&amp;gt; codigo em
javascript </desc>
</topico>
<topico>
<titulo>Exemplo 5 Executando construtor de
função&lt;br&gt;
</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Criar função sem nome&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;para calcular a multiplicação entre 2
numeros&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;executar no browser e mostrar em uma
pagina html&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;html&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;head&amp;gt;&lt;br&gt;
&amp;lt;title&amp;gt;pgm constroe funções &amp;lt;/title&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;script language=&quot;JavaScript&quot;&amp;gt;&lt;br&gt;
&amp;nbsp;&lt;br&gt;
// cria e executa uma função&lt;br&gt;
&amp;nbsp; &lt;br&gt;
&amp;nbsp; var f = new Function (&quot;x&quot;, &quot;y&quot;,&quot;return x * y;&quot;);&lt;br&gt;
&amp;nbsp; document.write(&quot;f = &quot; + f(2, 3) ); &lt;br&gt;
&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;ou pode
colocar o codigo dentro do head&lt;/span&gt;&lt;br&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;title&amp;gt;pgm constroe
funções &amp;lt;/title&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br&gt;
&amp;lt;script language=&quot;JavaScript&quot;&amp;gt;&amp;nbsp; // abre script javascript&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;var f = new Function (&quot;x&quot;,
&quot;y&quot;,&quot;return x * y;&quot;);&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/script&amp;gt;&amp;nbsp;&amp;nbsp;
&amp;lt;!...&amp;nbsp; fecha script&amp;nbsp; ....&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;script
language=&quot;JavaScript&quot;&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;document.write(&quot;f = &quot; + f(2, 3)
);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;// executa a função&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 1.:&lt;/span&gt;&lt;br&gt;
Copiar codigo acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 2:&lt;/span&gt;&lt;br&gt;
A declaração function não pode aparecer dentro de laços ou condições
(if). Já os literais de função podem.&lt;br&gt;
</desc>
</topico>
<topico>
<titulo>Exemplo 6 Executando literais de função&lt;br&gt;
</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Criar funções sem
nome&amp;nbsp; e &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;executar no browser e mostrar em uma
pagina html&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;br&gt;
Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;head&amp;gt;&lt;br&gt;
&amp;lt;title&amp;gt;pgm constroe e usa funções literais &amp;lt;/title&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;script language=&quot;JavaScript&quot;&amp;gt;&lt;br&gt;
//&amp;nbsp; executa a função literal&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;br&gt;
var f = function fatorial(x) {if (x &amp;lt;= 1) return 1; else return
x*fatorial(x-1);};&lt;br&gt;
document.write(&quot;fatorial de 4 = &quot; + f(4) ) ; &lt;br&gt;
&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;ou pode colocar o
codigo dentro do head&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;head&amp;gt;&lt;br&gt;
&amp;lt;title&amp;gt;pgm constroe e usa funções literais &amp;lt;/title&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;script language=&quot;JavaScript&quot;&amp;gt;&amp;nbsp; // abre script javascript&lt;br&gt;
&lt;br&gt;
var f = function fatorial(x) {if (x &amp;lt;= 1) return 1; else return
x*fatorial(x-1);};&lt;br&gt;
&lt;br&gt;
&amp;lt;/script&amp;gt;&amp;nbsp;&amp;nbsp; &amp;lt;!...&amp;nbsp; fecha script js&amp;nbsp;
....&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;script language=&quot;JavaScript&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
//&amp;nbsp; executa a função literal&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;br&gt;
document.write(&quot;fatorial de 4 = &quot; + f(4) ) ; &lt;br&gt;
&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 1.:&lt;/span&gt;&lt;br&gt;
Copiar codigo acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 2:&lt;/span&gt;&lt;br&gt;
Ela não cria uma função fatorial mas&amp;nbsp; permite que o corpo da
função faça referencia a si proprio usando este nome.&lt;br&gt;
</desc>
</topico>
<topico>
<titulo>Exemplo 7 Executando função como dado&lt;br&gt;
</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Passar funções como
argumentos para outras funções &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;&lt;br&gt;
&lt;br&gt;
Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;lt;html&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;head&amp;gt;&lt;br&gt;
&amp;lt;title&amp;gt;pgm constroe e usa funções literais &amp;lt;/title&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;script language=&quot;JavaScript&quot;&amp;gt;&amp;nbsp; // abre script javascript&lt;br&gt;
&lt;br&gt;
function ordemNumerica (a,b) {return a - b; }&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;lt;/script&amp;gt;&amp;nbsp;&amp;nbsp; &amp;lt;!...&amp;nbsp; fecha script js&amp;nbsp;
....&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;script language=&quot;JavaScript&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
//&amp;nbsp; executa uma função&lt;br&gt;
&amp;nbsp;&amp;nbsp; &lt;br&gt;
a = new Array(33, 4, 1111, 222);&lt;br&gt;
a.sort();&lt;br&gt;
document.write(&quot;classificação alfabetica = &quot; + a&amp;nbsp; ) ; &lt;br&gt;
document.write(&quot;&amp;lt;br /&amp;gt;&quot;);&lt;br&gt;
a.sort(ordemNumerica);&lt;br&gt;
document.write(&quot;classificação numerica = &quot; + a ) ; &lt;br&gt;
&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;/html&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;br&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 1.:&lt;/span&gt;&lt;br&gt;
Copiar codigo acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 2:&lt;/span&gt;&lt;br&gt;
A função sort aceita como argumento outra função que indica o tipo de
classificação&lt;br&gt;
</desc>
</topico>
<topico>
<titulo>Exemplo 8 Escopo de função&lt;br&gt;
</titulo>
<desc>&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Solução:&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;O corpo da função é
executado em um escopo local que difere do escopo global&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;. &lt;br&gt;
&lt;br&gt;
&lt;img style=&quot;width: 493px; height: 270px;&quot; alt=&quot;&quot; src=&quot;escopoFuncao.jpg&quot;&gt;&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Cria-se o escopo
adicionando o objeto de chamada na frente da cadeia de escopo. &lt;br&gt;
&lt;br&gt;
sintaxe --&amp;gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Objeto.funcao.metodo.propriedade(argumento)&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br&gt;
&lt;br&gt;
Objeto os construtores sempre começam com letra maiscula&lt;br&gt;
&lt;br&gt;
a palavra chave &lt;span style=&quot;font-weight: bold;&quot;&gt;this&lt;/span&gt; cria as
propriedades dentro de um construtor&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;span style=&quot;background-color: white; font-weight: bold;&quot;&gt;Código&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;span style=&quot;font-weight: bold;&quot;&gt;em
html e javascript:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
v&amp;lt;head&amp;gt;&lt;br&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
function msgErro (numeroErro, descricaoErro)&lt;br&gt;
&lt;br&gt;
{ &lt;br&gt;
document.write(&quot;Ocorreu um erro de execução:\nNumero do erro: &quot; +
numeroErro + &quot;\nDescricao do erro: &quot; + descricaoErro + &quot;\nNome da
variável: &quot; + this.descricaoErro); &lt;br&gt;
&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;br&gt;
&amp;lt;/head&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;lt;body&amp;gt;&lt;br&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
var ErroDivisao0 = &quot;Erro de divisão por zero&quot;;&lt;br&gt;
msgErro (34,ErroDivisao0);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
//var ErroDivisao = &quot;Erro de divisão por zero&quot;;&lt;br&gt;
//msgErro(34,ErroDivisao);&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;br style=&quot;background-color: white;&quot;&gt;
&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br&gt;
&lt;br&gt;
arguments.length!&lt;br&gt;
arguments[0]&lt;br&gt;
arguments.callee&lt;br&gt;
propriedade prototype&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgb(255, 102, 102);&quot;&gt;&lt;br&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Obs 1.:&lt;/span&gt;&lt;br&gt;
Copiar codigo acima para o endereço &lt;a href=&quot;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&quot; target=&quot;_blank&quot;&gt;http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2&lt;/a&gt;&amp;nbsp;
e testar&lt;br&gt;
&lt;br&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;br&gt;
</desc>
</topico>
</eventos>