So I am taking a Javascript course at my college, and I ran into two issues, the solutions to which, I've searched everywhere online for. I'll keep it short, because Im about to break my keyboard just thinking about this.
First difficulty:
var year = 2017;
var age = prompt("Please enter your age: ");
console.log("I was born in the year of " + (year - age));
var studying = prompt("Enter the number of years you expect to study in the college: ");
console.log("You will graduate from Seneca College in the year " + (year + studying));
Expected output:
1995
2019
Actual output:
1995
20172 //It seems to concatenate, regardless of how I try to add the year
and studying
together
Second difficulty:
function grader(x) {
switch (x) {
case (x < 50) :
console.log('Grade: F');
break;
case (x >= 50) :
console.log('Grade: D');
break;
case (x >= 60) :
console.log('Grade: C');
break;
case (x >= 70) :
console.log('Grade: B');
break;
case (x >= 80) :
console.log('Grade: A');
break;
default :
console.log('Error, invalid grade');
}
}
console.log("The letter grade is: " + grader (40));
Expected output:
The letter grade is: Grade F
Actual output:
Error, invalid grade
The letter graded is: undefined
Any help would be appreciated. I have no idea why I am running into these errors.