CPSC 1045: Assignment 4 [20 marks] Objectives: Practicing using alert, console.log() and different loops to solve problems Resources http://www.w3schools.com/js/js_loop_while.asp...


CPSC 1045: Assignment 4 [20 marks]



Objectives:




  • Practicing using alert, console.log() and different loops to solve problems







Resources




Overview


The purpose of today’s assignment is to create a JavaScript to practice writing information to the console. This lab will also allow you to practice using while loops and for loops and conditions.




  1. Create a new HTML file called a4.html. Add the usual tags to make a complete HTML file. In the head of this file add the following line of code:




  2. In the same directory, create a new JavaScript file called a4.js




  3. Inside a4.js complete the following exercises:




    1. Write the JavaScript to prompt the user to enter a string and a letter. Then, using a loop, you should determine how many times the letter appears in the string (both uppercase and lower case.
      Ex. If the user enters the string “Mischief managed!” and the letter “m” your console window should contain the following:
      The letter m appears 2 times in Mischief managed!




    2. Write the JavaScript that prompts the user to continuously enter numbers until a negative number is entered. Once a negative number has been entered, you should then print the average of all the entered numbers to the console. If the user does not enter any non-negative numbers (i.e., they only enter one number and it’s negative), you should alert the user with an error message.You must use a do while loop to solve this problem.

      Ex.If the user enters the numbers 7, 3, 5, 2, -1 you should print“The average is 4.25”
      Ex. If the user just enters -2 and no other numbers you should print“Error: No positive numbers entered”




    3. Write the JavaScript to prompt the user to enter an integer. Then you need to create the nested for loop that prints to the console the pattern shown below, where the number of rows and columns in the pattern is equal to the number entered by the user. You may assume the user will only enter numbers between 0 and 99. If you’re feeling adventurous, do a check to ensure the user only enters a number between 0 and 99.
      Ex. If the user enters the number 5 you need to print the following pattern to the console:
      ....1
      ...2.
      ..3..






.4...


5....
Whereas if the user had entered 3, you would print this:
..1


.2.
3..







    1. Test that your program works by opening the HTML file in the browser and checking the output in the console.





  1. Submissions




    1. Submit to D2L ONE zip/archive file containing the TWO files from this lab




    2. If you do not zip your files, you will receiveZEROfor this lab (http://www.wikihow.com/Zip-Files-Together)






  2. Grading
    Marks will be assigned as follows:




    1. 1 mark for correctly creating the HTML file and linking to JS




    2. 4 marks for proper indentation and good code quality




    3. 4 marks for correctly implementing exercise A




    4. 5 marks for correctly implementing exercise B – 0 if missing the do while




    5. 6 marks for correctly implementing exercise C





Jun 04, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here