Counting related items that match criteria

Comments

2 comments

  • Jacob Robinson

    I have attempted using the following js code but it returns 0 when it should be returning 1:

     

    var type = @All of Key Stage;
    var count = 0;
    for(var i = 0; i < type.length; i++){
    if(type[i] == "KS3"){
    count++
    }
    else{
    count
    }
    };

     

    Any anyone help?

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Jacob,

    the code looks ok, but you don't need the else-part:

    var type = @All of Key Stage;
    var count = 0;
    for(var i = 0; i < type.length; i++){
    if(type[i] == "KS3"){
    count++
    }};
    count

    Is Key Stage a single or a multi choice category? If multi choice: 

    if(type[i].indexOf("KS3") > -1 ){

    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk