Add a script element inside the body element, ideally at the bottom
Add an alert(“”); inside, with the string of your choice
inside the quotes. The example uses alert(“Hello, World!”); but you may
change the phrase if you wish.
Don't forget to end the line of JavaScript code with a semicolon!
Add a button element in the body with the following
attributes/values: type="button" onclick="returnExample();". Give it
some text as its content, like "Let's do a Return"
Create a script element at the bottom of your body element.
Create a function called returnMe() that does the following:
-declares a variable named examplePhrase and initializes it to a greeting (like "Hello")
-declares another variable, named examplePhrase2, and initializes it to a farewell message (like "Goodbye")
add a return statement concatenating examplePhrase and examplePhrase2
Create an additional function named returnExample() that does the following:
-declares a variable, finalPhrase, initialized with the value returnMe();
-uses an alert(); method call that shows finalPhrase to the user.
Create a basic one question quiz script that normalizes input to accept answers regardless of case.
There should be at least two answers accepted for the same question.
Use a logical or operator to set up a ternary/conditional
statement determining which message to show the user (one for a correct
answer, one for a wrong answer).
Use a workaround so "null" answers (empty input or if user
clicks "Cancel") aren't run through toUppercase() and don't break
anything.
This one introduces some new concepts--it may be helpful to review the video.
Give the body a background-color property with the style
attribute in its start tag, and an onclick event handler that triggers
an alert() that tells the user in some way that they clicked the body.
Create a div element inside the body of your page. Give it
a different, contrasting background color with the style attribute in
its start tag. Give it a width of 800px and a height of 400px, also
through the style attribute in its start tag. Finally, give it an
onclick event handler that triggers an alert() telling the user in some
way they clicked the div.
Create a button element inside the div element. Don't
forget to give it type="button" in the start tag to avoid compatability
issues. Give it an onclick event handler triggering an alert() that
tells the user in some way they clicked the button.
Click on each--the body (visible based on its
background-color), the div (visible based on its background-color), and
the button--and see what happens.
Create an HTML document with a script element in the body.
Prompt the user for an answer to something using a
prompt(); and accept input from them in a format you can then verify.
Make the question something with multiple possible answers (at least 2
different unique correct answers).
Using the various types of if statements you’ve learned so
far, make it so your script provides unique feedback for each correct
answer and one catch-all response for all incorrect answers. (You can
communicate this on the page, in alerts… your choice)
Feel free to refer back to the examples we’ve done so far and to your e-textbook.
Lab 14: the Lab That Wasn't
This is that one we started in class but that I didn't
have the correct code for saved and that we were thus unable to finish.
It counts as an automatic "full credit" lab for grading purposes--you
don't have to do/submit anything. It's on me. Sorry again about it not
working correctly!
Create an HTML document with a script element in the body.
Make a basic program that does SOMETHING with a switch statement and follows the following guidelines:
Your switch must have at least 3 specific “cases” and one “default,” so you must have at least 4 total.
You can get creative on the program’s
interactivity/purpose/theme/control flow, just make sure that each
“case” (including default) makes something happen that is visible to the
user—whether that’s in the form of an alert, document.write(), changing
the page itself, etcetera is up to you.
Feel free to refer back to the examples we’ve done so far and to your e-textbook.
From scratch, make your own form with your own names, ids,
for values, etc. Obviously we are not having it actually send the data
to a PHP page or a server, but you should code your form as if it is
(you may use a blank HTML page for the “action” property, or you may
simply put the URL in where it WOULD go).
You must use at least one text box, at least two radio buttons in the same group, at least two checkboxes, and a submit button.
For the applicable elements, you must use labels. Do not forget to use line breaks where required.
If you get stuck on anything, you may ask for help, use
W3Schools or some other online resource, or feel free to use
maininputs.html as a reference as well—it is a fully detailed, “correct”
example of all the form concepts we have learned today.
Make your own HTML page with at least 3 elements total.
Use any of the elements we’ve learned, or try new ones! Feel free to
reference your notes from before, any of our labs, W3Schools, Google,
etc… And remember that every single tag, element, and property we’ve
messed with in HTML officially so far (except for form stuff) is in
coolwebsite.html—feel free to use it as a reference as well.
Link an external stylesheet called “style.css” in the same folder. Remember att the top of styles.css to put @charset "UTF-8";
Use at least one class and one id to apply styling to certain elements of your choice.
As long as the styles you applied using class and id in
your stylesheet are visible in the HTML page in browser, you’ve
completed the lab successfully.
~~~
Lesson 6: The JavaScript Document Object Model (DOM)
Make a new HTML document. Add a script element to start, as always.
Make 3 clickable elements using onclick event handlers to
trigger 3 different functions (a button is easiest, but you may be
creative). Those functions should do as follows:
The first function should open a new window to another website of your choice.
The second function should do the same, but to a different website of your choice.
Finally, your third function should close either/both windows that were opened
Create a new HTML document and give it a script element, like usual.
You must include at least one image where, when an event
handler is triggered by the user, the image changes on the page to a
different image (it does not HAVE to change back, though that can be a
fun challenge). You have lots of examples to go by. Remember to
include the image files in your lab. You have to include the actual
image files in the zip as well as the html itself. If you
don’t, I won’t know if it actually works and won’t be able to grade it.
Add at least one other HTML element that has some style
property modified when the user interacts with it through an event
handler—ie text changes color with onhover. Use getElementById() for
this.
Make a new HTML document. Add a script element to start, as always, and an onclick event handler that will call your function.
Your script should do the following, inside a function:
query the user for their favorite word starting with a given letter (you may decide the letter)
If their word does start with that letter, give them
an affirmative response including that word. (ie. “Wow, I love
Armadillos too!”)
If their word does not start with that letter, repeat
the instructions and continue asking them until they give you a word
that meets your criteria
Your script must be case-insensitive—ie. if your letter was “A,” you must accept “armadillo” or “Armadillo”. However, you must use the same capitalization the user did when you repeat the word to them in your affirmative response.
Make a new HTML document. Add a script element to start,
as always, and an onclick event handler tied to a button that will call
your function--in this case, a method of a custom object you will create
for this lab.
Your script should do the following:
Make an object constructor
Give it at least 3 properties
Give it at least one method. This method should
display the properties of the object to the user in an easily
understandable format.
Make a named instance of that object with all properties properly initialized.
Make a new class using the “extends” and “super” keywords to pull your properties from the first class.
Include at least 1 method added in this new, second class. This
method should display the properties of the object to the user in an
easily understandable format if called by alert()
Make a named instance of that object with all properties properly initialized
Set up an alert() at the end that automatically calls your named instance’s method.
Make an HTML page with as many elements as you’d like (as long as
you can meet all requirements). They can be the same or different.
Give at least two the same class name, and give at least one an ID.
Make a button that, when clicked, changes a property of the
elements of the given class name, and that changes a different property
of the element with the ID. For the part that changes this based on
class name, use a for...of loop like in our recent examples.
EXAMPLE PROPERTIES YOU CAN USE: color (changes text color),
backgroundColor (changes background color), display (“block” or “inline”
shows it, “none” hides it), fontFamily/fontSize (change font
name/size). More at: W3Schools.
Make an HTML document with a script and one element with an onclick
event handler (it can be a button, an image, whatever—your choice). Do
not add any elements to the HTML itself beyond the script and this
clickable one! More will be added with JavaScript.
Make a script that includes the function that will be called by your
initial element's onclick event handler. This function should:
create a div using document.createElement() and add it to the body of the page using document.body.appendChild().
Append at least two other elements to this div, as “children,” using document.appendChild().
Add text to at least one of those “child” elements with document.createTextNode() and then document.appendChild().
Use Element.remove() to remove the original clickable element that
called this function—for instance, if it were a button, you would want
to make the button disappear when the rest of the page content appears.
~~~
Lesson 10: Developing Interactive Forms With JavaScript
Add at least 5 other form elements (input, textarea, etc)
within, divided between at least two fieldsets, each with their own
legend.
Make a basic confirmation page the form will direct the
user to upon submission (the value of the form element’s “action”
attribute). This can just be a basic message to the user.
Each element should have a name.
There must be at least one input element of the button
type which calls a function/script/statement that references another
element by its name using dot notation. (example1.html)
Similar to in the cookies1fixed.html example,
make a page that prompts the user for their name and then for a style
property’s value for an element of some sort—whether it’s a text-align
value for a div, font color for an h1, etc.
It cannot be for the background color—that is too close to the example.
Do not simply copy and paste the example and change a
couple things on it, either. You may use similar code to the examples,
but you must make this yourself and without copying/pasting.
Make it so a cookie is saved with the user’s name and the value the user provided for the element’s style property.
The style property of the element must be changed by
extracting it from the cookie directly, like in the script starting on
line 23 of cookies1.html. The page should change to reflect this style
change visually once the cookie is made.
Either by writing it to the page somewhere using innerHTML
or innerText OR by using an alert, show the cookie(s) that were created
to the user using document.cookie.