I hope that you have done this just correctly or at least try to find a solution or make it find even
a better solution for our task.
But anyway, let's go ahead and do it step by step.
So the first step was to create an array students instead.
There are four items, which should be objects and have three properties, name square ones, Corto
with the following values so right for students and pass the items as objects.
We need to open curly braces and that create the properties name.
John.
Then score one.
Forty seven.
And score to.
To six.
Let's copy it and paste three times.
We don't need this Colma here.
And also change the values right here, Bob.
And this course as twenty three and twenty four.
Then, Nick.
With course 40 and 35.
Elder law student Alex.
Change this course, you're right, 44 and 45.
All right, the first up is done.
The next is also very simple.
One, we just need to create two arrays for scores and degrees.
Let's do it.
Create variables cause.
And.
Let's place here as items the passing limit's 91 81.
One.
61 and 51.
Then create variable degrees and.
Insert.
Items.
A, B, c.
The anti.
OK, let's see what is the next step we need to create function which will calculate total score for
each student.
It's also the very simple step.
So create function and call it calculate some.
This function will receive two parameters for score one and score two, so let's place them in kind
of short way.
Then inside the braces create new variable sum and assign to score one plus score to.
And then in order to get the value some, we have to return it.
All right, I'm sure that you didn't have any trouble to come to this point.
Now it's time to start the main and more interesting part of this test.
So we need to create a function.
And using this function, we need to figure out which student has passed an exam and what kind of degree
of diploma he has got.
So creates new function and call it calculates final.
In order to see the results and also test the codes that we are going to write, let's call this function
right below the name of this function.
As you have just seen, we have created the general function for calculating the total score of students.
Now we're going to use follow up and emersion calculate some function in order to calculate the total
score for each student and after that at the results at the new property for our objects on the fly.
OK, let's do it first, create for Loop.
Variable, i.e., close to zero.
Then.
As a condition, right, I is less than students that length.
And then I plus plus.
As we said, we are going to act as the new properties, some of score one and score two, so.
Right students, I got some.
You remember that we were using dot notation in order to access and also to add the properties to objects,
you also see that calculate some function, returns the value some.
And in order to assign it to new property, we need to call this function here and pass at the arguments,
score one and score two for each student.
So right to calculate some.
And as an argument, right, students, I thought score one.
And then students I.
That's got to.
So, again, calculator function gives us as a value the sum of score one and score two, and we assign
it as a value to the newly created property.
Some, let's say, Castle, what this code exactly does.
Right, Castle?
That students.
Reload and you can see Arae with our objects, if you take a look, you will see that objects have a
new property, some with total scores for students.
And again, note that this property was created on the fly.
All right, now we need to check if a student has passed an exam or not, we know that overlimit is
51 points.
So we need to check if some, of course, is greater than or equal to 51.
So creative statement with the condition students, I thought some.
Is greater than or equal to 51.
If this condition is true, if a student has passed an exam, then log their result in council and write
Castlewood log.
Students I.
And use your name property.
Plus, past final exam.
Successfully.
Revolt and you see that we got results for three students, John, Nick and Alex, and he tells us that
they have passed final exams successfully.
All right, fine.
The next step is to figure out what was the final score for each student and according to that score,
what kind of degree of diploma this student has got for that, I'm going to use again, follow.
But before I do that, I want to demonstrate, just for your information, how Facebook works inside
another club that's right below.
A simple example.
But before that, let's make a little broader here.
So create follow up, right?
Very well, I.
And assigned to its Disvalue 100.
Then as a condition, right eye is less than.
Hundred and five.
And then I plus plus.
Inside the loop, create another one.
And.
Let's use here as a counter variable, X assigned to role, then right to condition X is less than 10.
And then X plus plus.
Let's log in council, the variable X.
And then.
Right outside Castle Deathlok.
I reload the page.
So you see, we have numbers from zero to nine and then 100, then again, numbers from zero to nine,
then hundred and one, and it continues like this until the condition becomes false.
Let's see what has happened.
Generally, people are sometimes confused with that case because they think that, well, first of all,
look, does its first iteration I mean, when I is 100, then the second follow up does one iteration
two.
But it's not true.
So when first loop does its first iteration, then for loop inside it does all its iterations.
You can obviously see it in this example.
So here during the first iteration, when I is 100, the following site does all the situations and
gives us the numbers from zero to nine.
And after that we have hundreds from the first iteration, which belongs to the first follow.
Makes sense.
OK, so we're going to use this case in our task, let's comment it out and go back to our task, create
another follow up and use.
Another counteracts assigned to it.
Zero.
We need this loop to iterate through a race course.
So I'm going to use length property, of course, right.
As a condition, X is less than Schaus thought length.
And that X plus plus.
Then we need to create another statement inside Fallujah using this statement, I'm going to compare
total scores of the students to scores which actually define a degree of the diploma.
So.
Right, if they're students, I.
Not some.
Is greater than or equal to Schaus X.
So if this condition is true, if total score of the student is greater than or equal to the items inside
a racecourse, then we need to get the result with the score and the degree which we need to get from
the eight degrees.
You see that both arrays have the same length and therefore, if total score is greater than one of
the items from scores, then we need to get its appropriate degree.
So, for example, if students score is greater than 91, then it's really what degree of diploma will
be a.
Makes sense, so we need to write the following cost a lot like.
Then.
He has.
And plus students, I told some.
Then again, plus some texture points and he got diploma.
With a degree.
And then plus, degrease ex.
Again, we use degrees with index number X because scores and degrees iRace have the same length.
Reload and you see that we got results that you may were not expecting.
Let's explain it.
In case of John, we know that John has 93 points, which is greater than all the items in a race course.
Therefore, the condition is true for all the iterations of.
And that's why we got five results instead of one.
So when the condition becomes true, then we need immediately to stop loop iterations.
And for that we need brake statements.
Let's reload, and he said that the problem is fixed.
OK, let's make your little border for better readability.
Reloj.
Now it's much nicer.
All right.
Almost everything is done, but you see that Bob is missing because he's failed and we need to show
it for that creative statement, which will be a part of first if statement where we have checked if
students have passed an exam or not.
And run in council.
Students.
I don't name plus got.
Then plus in place here with some of scores, students, I taught some.
And then plus points.
Has failed and has to try next year.
And then make again little border.
Reload the page and.
Here we have Bob to.
Now we can say that finally our task is done.
OK, I think that everything was clear for you, you can test again the code we have written on your
own.
Also, you can feel free to add something to improve this task.
I hope that you have enjoyed it and now little quiz is waiting for you, so let's move on.