indexOf. That is, write a function that takes as
parameters an array and a value and returns the index of the first
element that is equal to the value, or -1 if the value is not one
of the elements in the array.
Demonstrate your function on a page that asks the user for a color name and returns the index of that color in an array containing the 17 predefined CSS color names (in row order top-to-bottom, then left-to-right within a row).
function copyArray(a) {
return a;
}
Math or other
builtin functions. Demonstrate your function on a page
using the following values:
59 74 76 26 86 89 21 74 39 83
Math or other
builtin functions. Demonstrate your function on a page using the following values:
89 -35 11 -14 -31 -40 73 -40 -29 -81
Date object, but it really
doesn't have many useful methods. Let's build our own.
CalendarDate. It should take three
parameters: the day, month, and year of the date it
represents and store them in the constructed object
instance.
isChristmas() that tests whether
a CalendarDate is Christmas Day (December 25). A
test method like this always returns a boolean value (true or
false).
next() that increments
a CalendarDate instance to the next day. Note that
it is not enough to simply increment the day
field. Watch for special cases.
previous() that decrements
a CalendarDate instance.
increment(n) that increments
a CalendarDate by the given number of days. Note
that n can be positive, negative (in which case
it means decrement), or even zero.
CalendarDate
object with reasonable output to the page's document.
Person object.
It should take two parameters: the person's first and last
names and store them in the constructed object instance. It
should also setup additional properties
named bestFriend, and friends.
The first of these will hold a reference to
a Person object representing the person's best
friend. The latter should be an array that will hold references
to other Person objects representing all the
person's friends. Initialize these appropriately in your
constructor.
setBestFriend(person) that
takes as argument a (reference to a) Person
object and makes it the bestFriend of
the Person object on which the method is invoked.
addFriend(person) that
adds its argument (another Person object) to the
array of friends of the Person
object on which the method is invoked.
reciprocal(
reflexivein mathematical terms). In other words, if I'm your friend then you're my friend, and vice-versa. Adjust your methods to maintain the reciprocal relationships.
Person
object with reasonable output to the page's document.
Note: You may need some methods for printing the contents of the
arrays, if the defaults don't look good. Don't
forget Array.join in this context.
a[i]) can
be used in expressions like any other (scalar) variable.
undefined).
optionalparameters, which will have value
undefined if they weren't given in the invocation of
the constructor, but Javascript is not as flexible about this as
some other programming languages.
Last update: Monday, 01-Apr-2013 10:21:52 EDT