Difference between revisions of "Javascript"
Jump to navigation
Jump to search
(→An Example of a Web Page that asks the user for input and then produces some output) |
(→Code which times when user input is received, and uses fade-in of text) |
||
Line 42: | Line 42: | ||
</pre> | </pre> | ||
− | ==Code which times when user input is received, and uses fade-in of text== | + | ==Code which times when user input is received, and uses fade-in of text and has different style colors and fonts for differnet divisions of the webpage== |
+ | <pre> | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
<html lang="en"> | <html lang="en"> | ||
Line 141: | Line 142: | ||
showText(div2); // Fade-in effect for the second div | showText(div2); // Fade-in effect for the second div | ||
}, 3200); | }, 3200); | ||
− | |||
Line 152: | Line 152: | ||
</script> | </script> | ||
− | |||
</body> | </body> | ||
</html> | </html> | ||
+ | <pre> | ||
==What Javascript can't do== | ==What Javascript can't do== |
Revision as of 16:00, 6 September 2024
An Example of a Web Page that asks the user for input and then produces some output, and has different styles for different divisions of the output webpage
<h1>Printing "Happy Birthday, NAME INPUT" 8 Times</h1> <div id="output"></div> <!-- This is where we will display the output we create below --> <script> //Javascript has to go in a special script section. // Prompt the user for his name let name = prompt("What is your name?") ; //We will this variable later. let how_many=8; function new_line(){ // Select the output div let outputDiv = document.getElementById('output'); // Print Happy Birthday 8 times for (let i = 1; i <= how_many; i++) { outputDiv.innerHTML += "Happy Birthday, "+ name +"!<br>" ; } //The curly bracket shows this is the end of the loop; //Add some blank lines outputDiv.innerHTML += " <br><br><br><br><br>" ; } //The curcly bracket shows this is teh end of the function. //Run the function and print happy birthday 8 times. new_line(); // Prompt the user for a number of additional times to repeat happy birthday." how_many" is already declared, so no "let" is needed or allowed; how_many = prompt("How many times would you like to see that?") ; //Run the function again, after a .4 second delay. let timer = setTimeout(new_line, 400); </script>
Code which times when user input is received, and uses fade-in of text and has different style colors and fonts for differnet divisions of the webpage
<!DOCTYPE html>What Javascript can't do
*Javascript can't get rid of the "This page says" heading of windows it opens. This is a security anti-phishing feature, so people will know the question is coming from the Web, not from their apps. *Javascript can't put italics, boldface, color, etc. into prompt windows.