Maria's Computer explainer

Aim of the puzzle: Find the key information in a word problem.
Walk through of solution: Maria wants a function that figures out the total number of pixels on her computer monitor.

Knowing that the resolution of the screen is the number of pixels in width and height, a function that multiplies the width and height together will return the total number of pixels on the screen.
Sample code solution:

import {width, height} from 'monitor.resolution';

function totalPixels(w, h) {
    return w * h;
}

console.log(width + ' by ' + height);
console.log(totalPixels(width, height));

Javascript Concepts: Functions
Additional Code (hidden code that runs before the puzzle’s code):

let dim = pickRandom([
    [640,480],
    [768,480],
    [800,600],
    [1024,600],
    [1024,768],
    [1280,768],
    [1280,800],
    [1280,960],
    [1400,1050],
    [1600,1200],
    [1920,1080],
    [1920,1200],
    [1920,1280],
    [2560,1440],
    [2560,1600],
    [3840,2160],
    [3840,2400]
]);

let width = dim[0],
let height =dim[1],
1 Like

I cannot input width and height into the totalPixel

1 Like

Hey there,

To add a parameter to a function, tap on the underline inside the parentheses to bring up the keyboard. Then name your parameters, for example, w and h. Inside the function, refer to these parameters.

When the function is called, use width and height as the arguments.

Hope this helps!
Ben

2 Likes

Thank you,Grasshopper_Ben!

1 Like

I don’t know where I’m going wrong here

2 Likes

Hmm, your code looks fine to me. That should complete the puzzle. If you’re still having issues, try running the code a few times, then submit a bug report by tapping the menu button in the top-right of the puzzle screen.

Thanks for your patience!
Ben

1 Like

Im having the same problem

1 Like

So how can i pass this stage

1 Like

Replace the last line with

console.log(totalPixels(width,length));

1 Like

I swear :face_with_symbols_over_mouth: this is right

1 Like

Hey there, your function is correct, but it doesn’t looks like you’re calling it anywhere.

At the bottom of the code, call the function inside a console.log() (so the output gets printed), like this:

console.log(totalPixels(width, height))

Hope this helps!
Ben

4 Likes

Thanks
Grasshopper_ben

1 Like

I think I’m starting to get the hang of this. Break the question down into steps, write the function with parameters and variables, then be sure to call the function with the necessary arguments! What do you think? Thanks for all your help - really enjoying grasshopper! :slight_smile:

3 Likes

I can’t complete puzzle.
Seems like I do right. What wrong in my solution?

1 Like

Hey there, there’s a small bug in this puzzle, which should be fixed in our next release. In the meantime, try changing the function call to totalPixels(width, height).

Hope this helps!
Ben

2 Likes

Thank you.
All works now.

1 Like

When and where are values assigned to w and h?

I initially wanted to use width and height but the helper (?) wanted me to use w and h.

1 Like

The is that He should write first width and then height in the console.log
I had the same problem

1 Like

this works

I don’t know why , but I did this and it work
Add an empty console.log() at the bottom of the code and get the happy grasshopper :nut_and_bolt::wrench:

I don’t understand why I can’t just use width and height in the function. Why do they have to be renamed? This seems so inefficient and also makes no sense to me.