Combine variables and arithmetic to compute a student's weighted final score.
Weights: Homework 20%, Midterm 30%, Final 50%. Each weighted part is rounded down to a whole number before the parts are added.
You start with:
const homework: number = 90;
const midterm: number = 82;
const final_: number = 88;
Build:
Score: 86
Rules:
- Compute
score = Math.floor(homework * 20 / 100) + Math.floor(midterm * 30 / 100) + Math.floor(final_ * 50 / 100). - Each part is rounded down with
Math.floor(the third variable is namedfinal_). - For the starting data: 18 + 24 + 44 = 86.
- Print
"Score: "followed by the score, for exampleconsole.log("Score: " + score);
The third variable is named
final_. Wrap each part in Math.floor(...), for example Math.floor(homework * 20 / 100).
const homework: number = 90;
const midterm: number = 82;
const final_: number = 88;
const score: number = Math.floor(homework * 20 / 100) + Math.floor(midterm * 30 / 100) + Math.floor(final_ * 50 / 100);
console.log("Score: " + score);
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
