Ps 1
Ps 1
1. Event Handlers.
a) Create a JavaScript function named welcome that pops up an alert message that says
"Welcome!".
b) Create a button that calls the JavaScript function welcome when the user clicks it.
c) Create a block of text (can be in a div, p, header, ...) that calls the JavaScript function
welcome when the user moves the mouse pointer over it.
2. Write a JS that asks the user about how many random numbers they wish to generate. The
script then generates the numbers and calculates the average of the numbers and returns the
results to the user.
9. Write a function translate() that will translate a text into "rövarspråket". That is, double
every consonant and place an occurrence of "o" in between. For example, translate("this is
fun") should return the string "tothohisos isos fofunon".
10. Define a function sum() and a function multiply() that sums and multiplies (respectively)
all the numbers in an array of numbers. For example, sum([1,2,3,4]) should return 10, and
multiply([1,2,3,4]) should return 24.
11. Define a function reverse() that computes the reversal of a string. For example,
reverse("jag testar") should return the string "ratset gaj".
12. Represent a small bilingual lexicon as a Javascript object in the following fashion
{"merry":"god", "christmas":"jul", "and":"och", "happy":gott", "new":"nytt", "year":"år"}
and use it to translate your Christmas cards from English into Swedish.
13. You are about to create a JavaScript and HTML program (webpage) which is capable of
computing a student average grades as well returning its equivalent from his/her “First
Prelim,” “Second Prelim,” and “Final” grades. See the following screenshot for your
example:
Note: Name your Input/Output Objects base on its purpose as well your JavaScript
functions and from the result of student average (Semestral Grade); see the following
table for the range of values needed for its “Equivalent”.
Note: You need to create a JavaScript function (for “Compute” button) that will accept
user inputs for First Prelim, Second Prelim, and Final Term text fields as well to perform
a mathematical operation that will return the average of the three values to Semestral
Grade field and its equivalent to the following field. A “Clear” button and its function are
also necessary to prepare your interface for user’s next action. See the following for your
example:
14. Write a JS to perform the operation of a calculator.
Sample Object :
var library = [
{
title: 'The Road Ahead',
author: 'Bill Gates',
libraryID: 1254
},
{
title: 'Walter Isaacson',
author: 'Steve Jobs',
libraryID: 4264
},
{
title: 'Mockingjay: The Final Book of The Hunger Games',
author: 'Suzanne Collins',
libraryID: 3245
}];
Expected Output:
[[object Object] {
author: "Walter Isaacson",
libraryID: 4264,
title: "Steve Jobs"
}, [object Object] {
author: "Suzanne Collins",
libraryID: 3245,
title: "Mockingjay: The Final Book of The Hunger Games"
}, [object Object] {
author: "The Road Ahead",
libraryID: 1254,
title: "Bill Gates"
}]
42. Write a JavaScript function that creates a table, accept row, column numbers from the
user, and input row-column number as content (e.g. Row-0 Column-0) of a cell.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Change the content of a cell</title>
<style type="text/css">
body {margin: 30px;}
</style>
</head><body>
<table id="myTable" border="1">
</table><form>
<input type="button" onclick="createTable()" value="Create the table">
</form></body></html>