Guest User

Untitled

a guest
Feb 6th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. // 1. Create an HTML page with two buttons that argue with each other. When one button is clicked, the text "I'm right" should be placed next to it. When the other button is clicked, the text is replaced with, "No, I'm right!"
  2.  
  3. const button1 = document.querySelector('.cha-1-button1');
  4. const button2 = document.querySelector('.cha-1-button2');
  5. const text = document.querySelector('.cha-1-text');
  6.  
  7. button1.addEventListener('click', function() {
  8. text.innerHTML = 'I\'m right';
  9. });
  10.  
  11. button2.addEventListener('click', function() {
  12. text.innerHTML = 'No, I\'m right!';
  13. });
  14.  
  15. // 2. Create an HTML page with a large element on the page that says "Don't hover over me" inside of it. When you hover over the element, send an alert to the user that says, "Hey, I told you not to hover over me!"
  16.  
  17. const theDiv = document.querySelector('.cha-2-div');
  18.  
  19. theDiv.addEventListener('mouseover', function() {
  20. alert('Hey, I told you not to hover over me!');
  21. });
  22.  
  23. // 3. Create an HTML page with javascript that listens for a keypress.
  24. // When the user presses that key, the text of the H1 should show the value of the key they have pressed.
  25. // Example: If the user presses "J", the text inside the H1 should be "J".
  26.  
  27. document.addEventListener('keypress', function(e) {
  28. const text = document.querySelector('.cha-3-key');
  29. text.innerHTML = e.key;
  30. });
  31.  
  32. // 4. Create an HTML page with a form. The form should include inputs for a username, email, and password as well as a submit button.
  33. // In a Javascript file, write code that does the following things:
  34. // checks that the password is 12345678
  35. // checks that the username contains at least one number
  36. // if anything is wrong, send an alert message saying "incorrect"
  37. // Your page should also include an H1 tag. If the information in the form is correct, have Javascript change the text in the H1.
  38.  
  39. const formTitle = document.querySelector('.cha-4-heading');
  40. const username = document.querySelector('.cha-4-username');
  41. const password = document.querySelector('.cha-4-password');
  42. const submitButton = document.querySelector('.cha-4-submit');
  43.  
  44. submitButton.addEventListener('click', function(e) {
  45. e.preventDefault();
  46. const hasNumber = /\d/;
  47. if(password.value == 12345678 && hasNumber.test(username.value)) {
  48. formTitle.innerHTML = 'Thanks for signing up!';
  49. }
  50. else {
  51. alert('Please fill the fields out correctly.');
  52. }
  53. });
Add Comment
Please, Sign In to add comment