Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

ask for code in java script

i need some one Explains me this

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<script>

i need some one explane to me some part in the cod

1-what this mean

function print(message) {
  document.write( '<p>' + message + '</p>');
}

why we put message what is message is it keyword in java script or parameter and message in the document .write what mean

then

what this code mean there are 2 parameter in it but the function function print(message) hav one

but there are 2

print( search + ' is not in stock.'); 

var inStock = [ 'apples', 'eggs', 'milk', 'cookies', 'cheese', 'bread', 'lettuce', 'carrot', 'broccoli', 'pizza', 'potato', 'crackers', 'onion', 'tofu', 'frozen dinner', 'cucumber'];
var search;

function print(message) {
  document.write( '<p>' + message + '</p>');
}

while (true) {
  search = prompt("Search for a product in our store. Type 'list' to show all of the produce and 'quit' to exit");
  search = search.toLowerCase();
  if ( search === 'quit') {
    break;
  } else if ( search === 'list' ) {
    print( inStock.join(', ') ); 
  } else {
    if ( inStock.indexOf( search ) > -1 ) {
      print( 'Yes, we have ' + search + ' in the store.');
    } else {
      print( search + ' is not in stock.'); 
    }
  }
}
Samuel Webb
Samuel Webb
25,370 Points

I formatted your code to make it a bit easier for people to read. Please try to do this in the future. For information on how I did the code blocks, either go to 'edit question' or click the Markdown Cheatsheet at the bottom of the Add Comment and Add an Answer sections.

6 Answers

Gabriel Ward
Gabriel Ward
20,222 Points

Hi Moath,

Are you referring to

function print(message) { document.write( '' + message + ''); 
}

as the function with 2 parameters in it?

The piece of code

{ document.write( '' + message + ''); }

is not two parameters. It is the code the executes inside the function, which in this case accepts message as a parameter.

print( 'Yes, we have ' + search + ' in the store.'); there 3 1-'Yes, we have 2-search 3-in the store i mean this function print(message) message is parameter can i put moare than 1 in print() function

Gabriel Ward
Gabriel Ward
20,222 Points

I believe so,

function print(message, //another parameter can go here) { 
   document.write( '' + message + ''); 
}

What would you want to add?

thanks but what this cod do
document.write( '<p>' + message + '</p>'); i mean why the teacher put this code in the example

Gabriel Ward
Gabriel Ward
20,222 Points

It should actually be

document.write( '<p>' + message + '</p>');

This is added to the code to print a response to the user's answer. The answer is generated by the user entering a search into the prompt which comes from

while (true) { search = prompt("Search for a product in our store. Type 'list' to show all of the produce and 'quit' to exit"); search = search.toLowerCase(); if ( search === 'quit') { break; } else if ( search === 'list' ) { print( inStock.join(', ') ); } else { if ( inStock.indexOf( search ) > -1 ) { print( 'Yes, we have ' + search + ' in the store.'); } else { print( search + ' is not in stock.'); } 

i cant understand can you explane mor plz