473,378 Members | 1,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Please help me with ideas how to solve this task

5
Produce JavaScript code (and any necessary HTML) that will perform the following functions:
1. Using the prompt and alert functions, invite the user to input 5 marks (integers) in the range 0–100.
2. Calculate the average (mean) of the 5 marks as a rounded integer or a floating point number.
3. If the average mark is 0–39, then display a message saying that the grade is a Fail, 40–69 is a Pass, and 70–100 is a Distinction. If the value is less than 0 or greater than 100, display a message saying that there has been an input error.
Apr 16 '15 #1
9 1551
Dormilich
8,658 Expert Mod 8TB
1. use an HTML form with the number type input elements.
2. JavaScript only knows floats. simple way uses a loop, advanced way can use array functions
3. use if() conditions
Apr 16 '15 #2
fool1
5
please can you show example? I am stupid and new to JavaScript
Apr 16 '15 #3
Dormilich
8,658 Expert Mod 8TB
stupidity and newness are no excuse to not put in some effort.
Apr 16 '15 #4
fool1
5
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.     function promptForNumber( text)
  3. {
  4.     if(text == '' ){
  5.      text = "Please enter a number from 1 to 100";   
  6.     }
  7.     var number = parseInt(window.prompt(text, ""));
  8.     checkNumber(number);
  9.  
  10. }
  11. function checkNumber(number){
  12.  
  13.     if (number <= 100 && number >= 1) {
  14.  
  15. } else if (isNaN(number)) {
  16.     promptForNumber("Please enter a number from 1 to 100", "");
  17. } else {
  18.     promptForNumber("Your number (" + number + ") is not between 1 and 100", "");
  19. }
  20.  
  21. }
  22. </script>
Apr 16 '15 #5
Dormilich
8,658 Expert Mod 8TB
that’s definitely something to work on.

although there is a crucial unclearness in the task description. is the user supposed to input 5 numbers at once or one after another?

that would greatly influence your application design.
Apr 16 '15 #6
fool1
5
I beleive the numbers should be entered one after another and then button to calculate mean
Apr 16 '15 #7
Dormilich
8,658 Expert Mod 8TB
you will never come to use the button because you have one prompt after another.

if your input solely relies on prompts, then you must find a condition when to not show again a prompt. at that time (when no more input comes) you can start the calculation right away.

for me it would make more sense to use a form for input (and it would be more user-friendly as well), esp. since you have a defined number of inputs. additionally you could use the built-in validation.

I am aware that that would do away the prompt and alert functions altogether. but those shouldn’t be used for UI design anyways.
Apr 16 '15 #8
fool1
5
ok thanks a lot. what if the number are to be computed at once ? could help with some part of the code?
Apr 16 '15 #9
Dormilich
8,658 Expert Mod 8TB
first you need to get the numbers.

once you have the numbers together it doesn’t matter any more how you got them.
Apr 16 '15 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: rashika | last post by:
Hi : Can i call 2 procs within one task? I have sp_proc1 ? (and have declared one global variable as input parameter) now i have another sp_proc2 which uses same input parameter but if i...
5
by: Attila | last post by:
Hi. I am looking for a site or some coding ideas to run specific subs or programs at certain times and/or dates. For example, I would like to automate pulling data via ADO(.NET) at 6 am, on...
1
by: Andrej Hocevar | last post by:
Hello, below I've attached a test program reading data from a file and storing that information in a linked list. First problem is that current->p_name will print only the last item in the file...
2
by: Peter Row | last post by:
Hi, I have a VB6 webclass app that was ported to VB.NET. However due to multithreading now being used the global variables used have come to haunt me. Problem: I have a handful of global...
6
by: Federico | last post by:
Hi, this is what I can do: - Create new solutions using VS.Net ASP.Net - Save the solutions, build the solution, view in browser with the solution still open. But, once I close the solution, I...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
0
jautrus
by: jautrus | last post by:
I would like to have div tag over list box, not list box over div tag. I have this problem on many pages usually when I use drop down menus. I try to solve this problem with z-index but it doesn't...
7
by: DFS | last post by:
Before I build my own custom system, I wondered if anyone here has created or knows of some commercial systems (say for construction cost/time estimating) that help manage projects where some Task...
10
by: wazzup | last post by:
C++ is new to me and I'm trying solve this problem but get stuck. Please help me out. Below is the task and after that is what i got so far. Create a program to print nested squares Input:...
2
by: itsvineeth209 | last post by:
My task is to create login control without using login control in tools. I shouldnt use sqldatasource or any other. I should use only data sets, data adapters and data readers etc. U had created...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.