Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JavaScript / HTML - At the end of your web page, add a paragraph element titled Testing truthy and falsy - Create two input elements

JavaScript / HTML

- At the end of your web page, add a paragraph element titled "Testing truthy and falsy"

- Create two input elements labeled "Number Value 1" and "String Value 2"

- Give them the HTML attributes of id="value1" and id="value2".

- Both input elements should have type="number"

- Create a button element with the text "Not Strict" with id="testNotStrictButton"

- Create a button element with the text "Strict" with id="testStrictButton"

- Create a paragraph element with id="result"

- Include an embedded script at the bottom of the HTML page (use an embedded script for this exercise vs. an external script just for convenience sake). The script should do the following two functions, the first using an if-then construct and the second using a switch construct....

Function #1: testNotStrict

  1. create a function named testNotStrict
  2. within testNotStrict declare two variables to get the values of the two input boxes. (Hint: Use the value property to grab the value from an HTML input element.) NOTE: from a JavaScript perspective, it doesn't matter what type an input element has been declared in the HTML. The type attribute value changes the presentation of the input box to the user to limit the input to a number, date, valid email, so forth on the web page, but that's where the impact of the type attribute stops. Regardless of the input's type, the actual data in the input box is always passed to JavaScript as textual (string) data. This means that in order for JavaScript to evaluate the number in id="value1" as a number, it will need to be converted to a number in JavaScript. Use the parseInt() function to convert the value of id="value1" to a number in JavaScript.
  3. console.log the values of your two variables
  4. within testNotStrict compare the values from the two input boxes (now captured in your variables) using an if else construct and a not strict equality == comparison.
  5. display "Truthy" or "Falsy" in the paragraph with id="result" based on the comparison of the two values
  6. run testNotStrict from an event listener attached to the click event of the id="testNotStrictButton" button

Function #2: testStrict

  1. copy testNotStrict and paste it as a new function named testStrict
  2. delete the if else structure and code the same functionality back into the testStrict function using a switch construct with cases for true, false, and default. This time, test for strict equality === comparison and run case: true or case: false based on that strict comparison.
  3. test, debug these conditions...
    1. 0 and 0 -- Not Strict comparison is truthy; Strict comparison is Falsy
    2. 0 and nothing -- Not Strict comparison is truthy; Strict comparison is Falsy
  4. display "Truthy" or "Falsy" in the paragraph with id="result" based on the comparison of the two values
  5. run testStrict from an event listener attached to the click event of id="testStrictButton"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

What is a verb?

Answered: 1 week ago

Question

c. How is trust demonstrated?

Answered: 1 week ago

Question

Have issues been prioritized?

Answered: 1 week ago

Question

d. How will lack of trust be handled?

Answered: 1 week ago