Northcentral Technical College Introduction To Programming
10-152-310
Introduction to Programming with JavaScript NTC 10-152-310

Learning Plan 4 Divide Safely

# Example: Divide Safely

#### File: /Learning Plan 4/example-DivideSafely.html

### Problem Statement

> Write a program that asks a user to enter two numbers. If the second number is not zero then divide the first number by the second number and output the results to the page. If the second is zero then alert the user that they entered a zero and should try again. Do not output anything to the page if the second number is zero.

### The Program Planning Lists

    The List of Input Variables:
        numberOne
        numberTwo

    The List of Output Variables:
        numberOne
        numberTwo
        results

    The Process Checklist:
        prompt user for numberOne
        prompt user for numberTwo
        check numberTwo for zero
        alert user based on value
        divide numberOne by numberTwo
        output results

### The Test Plan

- Create a test plan for the program.

    TEST PLAN:

    Test Case 1:
        Inputs: 10, 5

        Expected Result: "10 divided by 5 is 2"

    Test Case 2:

        Inputs: 10, 0

        Expected Result: "You have entered a zero. Please try again."

    Test Case 3:

        Inputs: 1, 2

        Expected Result: 1 divided by 2 is 0.5

    Test Case 4:

        Inputs: 1, 2

        Expected Result: 354 divided by 267 is 1.3258427

### JavaScript Output

- Here's the code:
- Here's the output: