Reputation:
I make a condition with Else-If to print a line like [You got A+, You got D]. Now I want to store one valid output line in a variable outside the condition.
var gradeMark = Math.round(totalNumber / 6);
//Generate grade mark
if (gradeMark >= 80) {
console.log("You got A+");
} else if (gradeMark >= 70) {
console.log("You got A");
}....
.....
else if (gradeMark >= 0) {
console.log("You got F");
} else {
console.log("It's not valid mark");
}
//Getting grading mark
var validGradeMark =
Upvotes: 1
Views: 200
Reputation: 798
You can use defining variable instead of console log and it is out of condition now.
let gradeMark = Math.round(totalNumber / 6);
let validGradeMark;
// Generate grade mark
if (gradeMark >= 80) {
validGradeMark = "You got A+";
} else if (gradeMark >= 70) {
validGradeMark = "You got A";
}....
.....
else if (gradeMark >= 0) {
validGradeMark = "You got F";
} else {
validGradeMark = "It's not valid mark";
}
// Getting grading mark
console.log(validGradeMark);
Upvotes: 1