0

i have pretty basic question. sorry for that. I'm trying to build result point system for test. but there is that problem everything is printing together. there is a code:

    var g_Point = [8,9,10];
    var n_Point = [5,6,7];
    var b_Point = [1,2,3,4];

    var my_Points = 10;
    if(my_Points === g_Point){
        document.write('You Got Really Good Point');
    }else if(my_Points === n_Point){
        document.write('You Got Normal Points');
    }else if(my_Points === b_Point){
        document.write('You Got Really Bad Points');
    }

3
  • 1
    A number isn't equal to an array, which is what you're testing. It's not totally clear what you're trying to do, but if as I suspect it's to test which array the number (10 here) is included in, you want the includes method Commented Nov 26, 2020 at 20:24
  • So i have a points from one to ten. i want to give definiton to my point as a text, if i got points from 8 to ten, i want to output specific text. that was the question. Commented Nov 26, 2020 at 20:27
  • and if i write like this n_Point[0,1,2]? Commented Nov 26, 2020 at 20:27

1 Answer 1

2

You are not comparing two values, you want to check if a value is included in an Array, then use Array.prototype.includes():

var g_Point = [8, 9, 10];
var n_Point = [5, 6, 7];
var b_Point = [1, 2, 3, 4];

var my_Points = 10;
if (g_Point.includes(my_Points)) {
  document.write('You Got Really Good Point');
} else if (n_Point.includes(my_Points)) {
  document.write('You Got Normal Points');
} else if (b_Point.includes(my_Points)) {
  document.write('You Got Really Bad Points');
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.