0% found this document useful (0 votes)
18 views

Test2 Practice Questions

Uploaded by

jenemoy12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Test2 Practice Questions

Uploaded by

jenemoy12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Test #2 Practice Questions

Q1. What is a specific circumstance that is monitored by JavaScript and that a script can respond to in
some way called?

Q2. What value is written to the console when the following code executes?
let sentence = "Jack and Jill went up a hill."
console.log(sentence.search("."))

Q3. What is the output from the following lines of code?

let re = /\d{3}-\w\d{2}/
console.log(re.test("420-H20"))

Q4. What is the syntax to update an element called myEl to have the font size of 4em? (Refer to the
notes on updating HTML or check out this site - https://alvarotrigo.com/blog/change-css-javascript/)

Q5. Write the JSON form for the following student data (Refer to the labs on Classes and Objects)

firstname = “John”, lastname = “Alexander”, age=17


firstname = “Maria”, lastname = “Ross”, age=18

Q6. Write the regular expression that satisfies the following conditions:

(i) A string containing 3 numbers in a row


(ii) A string where the third to last character must be A, B or C
(iii) A string that represents a valid Canadian Postal Code

Q7. The file index.html contains a form with 4 fields and a submit button. The HTML file has also been
linked to index.js in the js folder. All your javascript goes in this file (you cannot change the HTML). The
HTML form has 3 text fields and 3 radio button and a submit button. You need to validate each of them
as per the instructions below (use regular expressions where appropriate/necessary):

(i) Add a function called validateForm that is called by an event handler when the form is
submitted. The function validates each of the fields in the form and submits the form if all
the fields are valid. This function must call the functions that validate each of the individual
fields and must not duplicate their code
(ii) Add functions called validateFieldName that is called by an event listener when the field
value changes. The function validates the field and returns true or false.
(iii) The username field validation is the field between 6 and 10 characters long (inclusive). It
contains only upper- and lower-case letters
(iv) The userId field validation is:
a. Starts with either a S, T, or V
b. Followed by 4 digits
c. Followed by any 3 lowercase letter
d. Followed by an optional letter X or x
e. There are no other characters (so S7534ksf is valid as is T4928ikrX, but V35asff is not)
(v) The licence field validation is:
a. Contains only numbers
b. Must contain the numbers 789 (in that order, but not necessarily sequential)
(vi) The level field validation is: one of the radio buttons must be selected
(vii) Use a while loop to check the radio buttons and stop the loop as soon as you determine that
a button has been pressed
(viii) Each function must display an error message indicating the field in error in the span tag
corresponding to the field.
(ix) Make sure that the error message is removed when the field is valid
(x) When the field contains an error, add the class errorClass to the input field. When there is
no error, remove the class errorClass from the field (the class already exists in the CSS file)

Q8. Practice the Part A of Labs 4a, 4b and Lab 5

You might also like