let grade = +prompt(“what number score did you receive on the test?”)
if(grade = 91 || 92 || 93 || 94 || 95 || 96 || 97 || 98 || 99 || 100){
printToScreen(“The grade is an A”)
}
if(grade = 81 || 82 || 83 || 84 || 85 || 86 || 87 || 88 || 89 || 90){
printToScreen(“The grade is an B”)
}
if(grade = 71 || 72 || 73 || 74 || 75 || 76 || 77 || 78 || 79 || 80){
printToScreen(“The grade is an C”)
}
if(grade = 61 || 62 || 63 || 64 || 65 || 66 || 67 || 68 || 69 || 70){
printToScreen(“The grade is an D”)
}
if(grade = 51 || 52 || 53 || 54 || 55 || 56 || 57 || 58 || 59 || 60){
printToScreen(“The grade is an E”)
}
if(grade = 41 || 42 || 43 || 44 || 45 || 46 || 47 || 48 || 49 || 50){
printToScreen(“The grade is an F”)
}
// DO NOT ALTER CODE WRITTEN BELOW THIS LINE
function printToScreen(text) {
let r = Math.floor(Math.floor(Math.random() * 255 + 1));
let g = Math.floor(Math.floor(Math.random() * 255 + 1));
let b = Math.floor(Math.floor(Math.random() * 255 + 1));
const svg = d3
.select(“body”)
.append(“svg”)
.attr(“width”, 1500)
.attr(“height”, 75);
svg
.append("text")
.attr("y", 37.5)
.attr("width", 450)
.attr("height", 75)
.attr("x", -1000)
.attr("font-weight", "bold")
.attr("font-size", "20px")
.attr("fill", `rgb(${r},${g},${b}`)
.attr("font-family", "Roboto")
.text(text)
.transition()
.duration(1000)
.attr("x", 37.5);
}
May i know the proble you are experiencing?
yeah sure. Sorry im just learning from a course and they told me to do a project and my code doesnt work: Heres the link https://codepen.io/coderkoji/pen/QWKgmJb
my ifs statements arent working because they print all the answers instead of 1
no matter what you type in
You should change your code to
If(grade > 50 && grade < 60){
PrintToScreen(grade);
}else if(grade > 60 && grade < 70){
Printtoscreen(grade);
}else if(and so on…)
Do the same with the other else if condition
ok lemme try that to see if that works
1 Like
thanks so much. Could you please explain to me whats the difference between this and the previous code so i dont make this mistake again
You use else if after if condition if you only want one condition to pass from a list of if conditions.
You use > to chrck if first value is greater than the second calue
And the < to check if first value is les tthan the second
Like if this condition is not true go to the next else if if not true again go to the next
If its true skip all the else if or else conditions.
ok thanks so much for helping me. really appreciate the help
robm99x
December 21, 2020, 8:37pm
11
let grade = +prompt(“what number score did you receive on the test ?”)
function toGrade(numGrade) {
if (grade >= 91 && grade <= 100) {
return 'A';
}
if (grade >= 81 && grade <= 90) {
return 'B';
}
if (grade >= 71 && grade <= 80) {
return 'C';
}
if (grade >= 61 && grade <= 70) {
return 'D';
}
if (grade >= 51 && grade <= 60) {
return 'E';
}
if (grade >= 41 && grade <= 50) {
return 'F';
}
return `unknown grade(${numGrade})`;
}
printToScreen('The grade is an ' + toGrade(grade));
// DO NOT ALTER CODE WRITTEN BELOW THIS LINE
function printToScreen(text) {
let r = Math.floor(Math.floor(Math.random() * 255 + 1));
let g = Math.floor(Math.floor(Math.random() * 255 + 1));
let b = Math.floor(Math.floor(Math.random() * 255 + 1));
const svg = d3
.select(“body”)
.append(“svg”)
.attr(“width”, 1500)
.attr(“height”, 75);
svg
.append("text")
.attr("y", 37.5)
.attr("width", 450)
.attr("height", 75)
.attr("x", -1000)
.attr("font-weight", "bold")
.attr("font-size", "20px")
.attr("fill", `rgb(${r},${g},${b}`)
.attr("font-family", "Roboto")
.text(text)
.transition()
.duration(1000)
.attr("x", 37.5);
}