Working in Stem Explainer

Aim of the puzzle: Use Apps Script to count how many times the same value appears in a spreadsheet from Sheets.

Walk through of the solution: In this puzzle, you’ll use Apps Script to count values in a spreadsheet and figure out how many customers are paying in stems.

To complete the puzzle, add an if statement inside the nested for…or loop that checks if cell === 'stems'. Then, inside the code block {} of the if statement, add stemCount++.

Sample code solution:

let id = '1QE4pZs8efMoHKGOEHyXGT_nPZf1b_Sw7ssFCk2J2ueo';
let sheet =  SpreadsheetApp.openById(id);
 
let values = sheet.getRange('B1:B8').getValues();
let stemCount = 0;
for (let row of values) {
    for (let cell of row) {
        if (cell === 'stems') {
            stemCount++;
        }
    }
}
console.log(stemCount + ' customers are paying with stems.');

JavaScript concepts: Variables, Strings, Numbers, For…of Loops, Strict Equality Operator, Increment Operator
Apps Script concepts: SpreadsheetApp, .openById(), .getRange().getValues()


what is the problem here .Please help ASAP

Hello, @sreyansh_dash, all I see is one tiny problem.
When you made your if statement, you forgot to put your bracket ({}).

for (let row of values) {
for (let cell of row) {
if (cell === 'stem') {
stemCount++;
}
}
}

As you can see, before and after the stemCount++, I put brackets to show that it is inside the code block of the if statement.
Hope this helps!
-Friidays :smile:

Hi! I have been trying this same exact answer even before seeing it was correct on here and I am still getting an error message saying that I am missing a bracket in my if statement but I am not. I have written it multiple times and have compared it several times to the screenshots and answer key provided and it is identical, but it is not accepting it.