100% encontró este documento útil (1 voto)
34 vistas3 páginas

Ejercicios Resueltos de JavaScript

El documento contiene 6 ejemplos de código JavaScript. El primero y segundo ejemplo muestran números pares e impares del 0 al 100 utilizando bucles for. El tercero solicita un número al usuario y muestra su tabla de multiplicar. El cuarto elimina la funcionalidad del botón derecho del ratón. El quinto abre nuevas ventanas del navegador. Y el sexto proporciona un botón para imprimir la página web.
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
100% encontró este documento útil (1 voto)
34 vistas3 páginas

Ejercicios Resueltos de JavaScript

El documento contiene 6 ejemplos de código JavaScript. El primero y segundo ejemplo muestran números pares e impares del 0 al 100 utilizando bucles for. El tercero solicita un número al usuario y muestra su tabla de multiplicar. El cuarto elimina la funcionalidad del botón derecho del ratón. El quinto abre nuevas ventanas del navegador. Y el sexto proporciona un botón para imprimir la página web.
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd

EJERCICIOS RESUELTOS JAVASCRIPT

1.- Crea un cdigo javascript que permita mediante un bucle mostrar por pantalla los nmeros pares del 0 al 100

<html> <body> <script language='javascript'> // muestra numeros pares del 0 al 100 var a=0; for (a=0;a<=100;a++) { [Link]('primer valor del bucle '+a+"<br>"); a++; } </script> </body> </html>

2.- Crea un codigo javascript que permita mediante un bucle mostrar por pantalla los numeros impares del 1 al 99

<html> <body> <script language='javascript'> // muestra numeros impares del 1 al 99 var a=0; for (a=1;a<=100;a++) { [Link]('primer valor del bucle '+a+"<br>"); a++; } </script> </body> </html>

3.- Crea un script que solicite al usuario un numero y muestre la tabla de multiplicar del numero introducido.

<html> <body> <script language='javascript'> // muestra la tabla de multiplicar var a=prompt('Que tabla de multiplicar quieres? '); var b=0; for (b=0;b<=10;b++) { [Link]('--> '+a+' * '+b+'='+b*a+"<br>"); } </script> </body> </html>

4.- Este codigo elimina el funcionamiento del boton derecho del raton:

<html> <head> <title> Desactivo Boton derecha del raton </title> <script language="JavaScript"> function controlraton() { if ([Link]==2) { alert ('Temporalmente desactivado.') } } [Link]=controlraton </script> </head> <body> <center> Intenta pulsar el boton de la derecha del RATON </center> </body> </html>

5.- Este codigo abre una nueva ventana del navegador:

<html> <head> <title>Curso Javascript [Link]</title> </head> <body bgcolor="green"> <center> <br> <form> <input type="submit" value="Ventana con barra direcciones" onclick="[Link]('[Link] <input type="submit" value="Ventana con barra de estado" onclick="[Link]('[Link] <br> <input type="submit" value="Ventana con barra de direcciones y estado" onclick="[Link]('[Link] </form> </center> </body> </html>

6.- Script para colocar un boton para imprimir la pagina web,

<html> <head> <title>Cursos [Link]</title> </head> <body bgcolor="yellow"> <center> Mediante el siguiente boton imprimiremos la pagina web <br> <form> <input type="submit" value="Imprimir Pagina" onclick="javascript:[Link]()"> <br> </form> <br> o tambien podemos utilizar un link <br> <br> <a href="javascript:[Link]()">Imprimir Pagina Web</a> </center> </body> </html>

Common questions

Con tecnología de IA

To open a new browser window with a specified configuration in JavaScript, the 'window.open()' method is used along with parameters that specify the URL, a window name, and a features string. The features string can include options like 'location', 'status', 'width', and 'height' to customize the appearance and functionality of the new window. For instance, 'window.open('http://www.luisbonilla.com','','location=yes,width=300,height=400')' opens a window with specified dimensions and a location bar .

JavaScript can print a webpage using the 'window.print()' function. This function can be called directly from a button or a hyperlink. For the button method, an 'input' element of type 'submit' can include 'onclick="javascript:window.print()"'. For the link method, an 'a' element can link to 'javascript:window.print()'. Both methods trigger the browser's printing capabilities when clicked .

To display odd numbers from 1 to 99, start by initializing the variable 'a' to 1. Use a for loop to iterate over the range with 'for (a=1; a<=100; a++) { a++; }'. In each iteration, document.write is used to output the current value of 'a', which would represent all odd numbers. This method increments 'a' by 2, effectively skipping even numbers .

A multiplication table can be created by first using 'prompt()' to ask the user for a number. Then, a 'for' loop runs with a counter variable from 0 to 10. Within the loop, the document.write function is used to display the multiplication of the user-provided number with the counter variable, formatted as 'number * counter = result'. For example, if the user inputs '2', the script displays '2 * 0 = 0', up to '2 * 10 = 20' .

Disabling right-click with JavaScript can prevent certain user actions, like copying content, but it also has security implications. It may disrupt standard user navigation and lack effectiveness as a security measure, given that it can be bypassed using browser settings or scripts. Over-relying on such measures without server-side support poses a false sense of security .

JavaScript can display even numbers from 0 to 100 using a for loop by incrementing the variable 'a' by 2 each iteration. The essential code structure involves initializing a variable 'a' to 0, using a for loop: 'for (a=0; a<=100; a++)', and incrementing 'a' by 2 within the loop, ensuring even numbers are shown. The document.write function is then used to display the current value of 'a' at each iteration .

JavaScript scripts customize new windows by specifying parameters in 'window.open()'. This method takes a URL, a window name, and a string indicating features like 'width', 'height', 'location', and 'status'. Developers can tailor these features to match the visual requirements of the application, making new windows better integrated in terms of size and tool availability .

JavaScript uses the 'document.onmousedown' event to manage mouse interactions. Assigning a function to this event enables execution whenever a mouse button is pressed, such as preventing right-click menus. This approach allows for real-time monitoring but can degrade user experience if overused, and is vulnerable to being overridden by future events unless properly designed .

The 'javascript:' prefix in an 'href' makes the link behave as an executable script rather than a navigation instruction. It's vital for ensuring that actions like triggering 'window.print()' execute immediately when the hyperlink is clicked, without navigating to a different URL. It thereby integrates functionalities like printing directly into clickable elements .

A JavaScript function can prevent the right-click context menu by intercepting the 'onmousedown' event, and specifically checking if the right mouse button (event.button==2) is pressed. If so, a custom alert message can be triggered. This is achieved by assigning the function 'controlraton' to 'document.onmousedown', ensuring that any mouse click will trigger this function .

También podría gustarte