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') {
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') {

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.
Please help!

Hi there Gabriela_Matheu,

Am wondering if you got you reponse to your screenshot coz also getting the same outcome.
Please help coz I have been here for two whole days…

Thank you,
Below coder (Kgotso_Malefetse)

Just saw my mistake thank you… :grinning: :grinning:

Sorry for the late reply!
I hadn’t been on in a few days. I turned on my notifications though in case we run into another problem and we can try and work it out together. I’m really new at this right now and wouldn’t mind a study buddy.

Hi Gabriela_Matheu

Thank you for being my study buddy. To let the truth I love programming and really struggle a lot with it. I can’t wait to start.

Enjoy your day

eu estava esquecendo de colocar parênteses na if… só percebi o erro depois de ver aqui