Question
Copy ct_Ex8.html and ct_Ex8.js to new files named ct_Ex9.html and ct_Ex9.js. In this exercise, you translate your flowchart of Ex9 of Part 1 to its
Copy ct_Ex8.html and ct_Ex8.js to new files named ct_Ex9.html and ct_Ex9.js. In this exercise, you translate your flowchart of Ex9 of Part 1 to its equivalent JavaScript code. You need to make changes in your ct_EX9.html including: js script link, header text, and name of the event function digits37(). In the js file of previous exercise, you (should have) separated digits of a number by modulus and division operators. Now, in ct_Ex9.js, you need to make the following changes
Name of the function should be digits37()
Change the output message from its digits to number of 3 or 7s
Implement the function based on your flowchart.
Once you are done, run the program, you should see the following results if you enter 789041 or 5323653345. If not, debug your code.
------flowchart was-----
Devise a flowchart to receive a positive integer number and output how many of its digits are equal to 3 or 7. For instance, if the input is 772, the program should output 2, because there are two 7 there. In another example, if the input is 14367, the program should output 2 as there is a 3 and a 7 in it. Hint, before entering the loop, declare a counter variable and assign 0 to it. Inside the loop, update the counter when necessary. Output the value of the counter variable after the loop.
Hint, you can use if elseif to check conditions, or use logical OR in the condition to make the code more succinct.
------html----
# of 3 and 7's in digits of a positive number
-----js------
// For: 23w EECS1012N, York University, Lassonde School of Engineering (LAS)
// in Ex7 to Ex13, change the name of the following function properly
function separateDigits() {
var outputObj = document.getElementById("output");
// this statement receives some data and parses it to integer
var a = parseInt(prompt("Please enter a number: ", ""));
var digits="";
var number=a;
if(number <=0){
digits="Enter number greater than 0";
} else
{
while(number>0){
var d=number%10;
digits+=d+",";
number=Math.floor(number/10); }
}
/* this statement add some message to our output Object used for Ex8
you would need to change the message to be appropriate in Ex9 to E13 */
outputObj.innerHTML = "number: " + a + " its digits: " +digits; // uncomment this line for Ex8
// translate the rest of your flowcharts to js here:
// factorial_B(a); // for Ex11 call function factorial_B, passing a
//the following statements inform the user that the program ended
//and disable the button. Ctrol+F5 to refresh the browser in order to start over
outputObj.innerHTML = outputObj.innerHTML + " " + "program ended";
document.getElementsByTagName("button")[0].setAttribute("disabled","true");
}
// for Ex11 take input named num and computer num!
/*factorial_B (num) {
// num is the input, calculate factorial of num. Use num as variable name.
var outputObj = document.getElementById("output");
}*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started