text: // This example uses the Sentinel-2 QA band to cloud mask
  // the collection.  The Sentinel-2 cloud flags are less
  // selective, so the collection is also pre-filtered by the
  // CLOUDY_PIXEL_PERCENTAGE flag, to use only relatively
  // cloud-free granule.
  
  // Load Sentinel-2 TOA reflectance data.
  var s2 = ee.ImageCollection('COPERNICUS/S2');
  
  // Function to mask clouds using the Sentinel-2 QA band.
  function maskS2clouds(image) {
    var qa = image.select('QA60');
  
    // Bits 10 and 11 are clouds and cirrus, respectively.
    var cloudBitMask = ee.Number(2).pow(10).int();
    var cirrusBitMask = ee.Number(2).pow(11).int();
  
    // Both flags should be set to zero, indicating clear conditions.
    var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
               qa.bitwiseAnd(cirrusBitMask).eq(0));
  
    // Return the masked and scaled data.
    return image.updateMask(mask).divide(10000);
  }
  
  // Map the function over one year of data and take the median.
  var composite = s2.filterDate('2016-01-01', '2016-12-31')
                    // Pre-filter to get less cloudy granules.
                    .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
                    .map(maskS2clouds)
                    .median();
  
  // Display the results.
  Map.setCenter(-2.04, 48.6411, 13);
  Map.addLayer(composite, {bands: ['B3', 'B2', 'B1'], min: 0, max: 0.3});
  
  