Skip to content

Instantly share code, notes, and snippets.

@RuyiLi
Created August 6, 2019 02:19
Show Gist options
  • Save RuyiLi/0b672bcd0503877621784d3f81a17b5b to your computer and use it in GitHub Desktop.
Save RuyiLi/0b672bcd0503877621784d3f81a17b5b to your computer and use it in GitHub Desktop.
More Assignments

Assignment 1 - Age

Create an input with type="date". When a button is pressed, the program should write "You are $(age) years old" into a paragraph element. Replace $(age) with the number of years since the date entered.

Use the MDN Docs for the Date object to complete this assignment: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

You can get a date object from the input by doing new Date(input.value).

Assignment 2 - Move a Square

Create a div with width 100px, height 100px, position fixed, top 50px, left 50px. Create four buttons labelled "up", "down", "left", and "right". When one of these buttons is pressed, the square should move 10px in the respective direction. DO NOT TRY TO DO SOMETHING LIKE div.style.top += 10. The style should take a string consisting of a number followed by "px", not just a number.

Assignment 3 - Move a Square Except With an Input

Create a div with width 100px, height 100px, position fixed, top 50px, left 50px. Create an input with type text. When something is typed into this input, it should perform a certain action. If W is pressed, the square should move 10px up; if A is pressed, the square should move 10px to the left; D, 10px to the right; S, 10px down. All other keys can be ignored. Remember to clear the input after each keypress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment