Guest User

Untitled

a guest
Feb 17th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. window.onload = function() {
  2. const buttons = document.querySelectorAll('.exercise button');
  3. const largeElemet = document.getElementById('myElement');
  4. const myText = document.querySelectorAll('.exercise h1');
  5. const mySubmit = document.getElementById('submit');
  6.  
  7. for (i = 0; i < buttons.length; i ++) {
  8. addTextListener(buttons[i]);
  9. };
  10. addHoverListener(largeElemet);
  11. addKeyPressListner(myText[0]);
  12. addUserValidationListener(submit);
  13.  
  14. //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!"
  15. function addTextListener (node) {
  16. node.addEventListener('click', function(e) {
  17. let newText = document.getElementById('newText');
  18.  
  19. if (newText === null) {
  20. newText = document.createElement('p');
  21. newText.setAttribute('id', 'newText');
  22. console.log(document.querySelector('.exercise'));
  23. document.querySelector('.exercise').appendChild(newText);
  24. };
  25.  
  26. if (this.id === 'buttonOne') {
  27. newText.innerHTML = 'I\'m right';
  28. } else if (this.id === 'buttonTwo') {
  29. newText.innerHTML = 'No, I\'m right';
  30. };
  31. });
  32. };
  33.  
  34.  
  35. //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!"
  36. function addHoverListener (node) {
  37. node.addEventListener('mouseover', function(e) {
  38. alert('Hey, I told you not to hover over me!');
  39. });
  40. };
  41.  
  42.  
  43. //Create an HTML page with javascript that listens for a keypress.
  44. // - When the user presses that key, the text of the H1 should show the value of the key they have pressed.
  45. // - Example: If the user presses "J", the text inside the H1 should be "J".
  46. function addKeyPressListner (node) {
  47. console.log(node);
  48. document.addEventListener('keypress', function(e) {
  49. const keyName = e.key;
  50. console.log(e);
  51.  
  52. let hText = document.getElementById('emptyHeader');
  53. console.log(hText);
  54. hText.innerHTML = keyName;
  55. })
  56. }
  57.  
  58. //Create an HTML page with a form. The form should include inputs for a username, email, and password as well as a submit button.
  59. function addUserValidationListener (node) {
  60. node.addEventListener('click', function(e) {
  61. const username = document.getElementById('userId').value;
  62. const password = document.getElementById('userPswd').value;
  63. const email = document.getElementById('userEmail').value;
  64. let loginSuccessMsg = document.createElement('h1');
  65. if (username.search(/[0-9]/) !== -1 && password==='12345678') {
  66. alert('login successful!')
  67. } else {
  68. alert ('incorrect!')
  69. }
  70.  
  71. })
  72. }
  73.  
  74.  
  75. };
Add Comment
Please, Sign In to add comment