Skip to content
FrontDepth, Home

Back to the topic

Practice: Core Web Vitals: LCP, CLS and INP

Answer first, then compare. Rate yourself honestly — it drives your weak-areas list.

2 predict-output · 3 open

Questions up to level

Shows questions up to the selected level.

No practice questions for this level yet.

  1. Predict the outputJunior

    The array holds the INP values (in ms) of eight visits to a page. The code computes the mean and the 75th percentile (nearest-rank method). What does it log?

    JavaScript
    const inp = [240, 60, 300, 90, 70, 260, 100, 80];
    
    const sorted = [...inp].sort((a, b) => a - b);
    const mean = inp.reduce((sum, ms) => sum + ms, 0) / inp.length;
    const p75 = sorted[Math.ceil(sorted.length * 0.75) - 1];
    const goodVisits = inp.filter((ms) => ms <= 200).length;
    
    const rate = (ms) => (ms <= 200 ? "good" : ms <= 500 ? "needs improvement" : "poor");
    
    console.log(mean);
    console.log(rate(mean));
    console.log(p75);
    console.log(rate(p75));
    console.log(goodVisits + " of " + inp.length);
  2. Open questionJunior

    What are the Core Web Vitals, what does each one measure, and when does a page pass?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.

  3. Predict the outputMiddle

    The array lists the layout shifts of one visit (time in ms since navigation, shift score, and the hadRecentInput flag). The loop applies the CLS session-window rules. What does it log?

    JavaScript
    const shifts = [
      { time: 400, value: 0.03, hadRecentInput: false },
      { time: 1100, value: 0.04, hadRecentInput: false },
      { time: 2600, value: 0.2, hadRecentInput: true },
      { time: 3000, value: 0.04, hadRecentInput: false },
      { time: 3800, value: 0.05, hadRecentInput: false },
      { time: 4600, value: 0.03, hadRecentInput: false },
      { time: 8200, value: 0.05, hadRecentInput: false },
    ];
    
    let windows = 0;
    let current = 0;
    let windowStart = 0;
    let lastTime = -Infinity;
    let cls = 0;
    let total = 0;
    
    for (const shift of shifts) {
      if (shift.hadRecentInput) continue;
      total += shift.value;
      const sameWindow = shift.time - lastTime < 1000 && shift.time - windowStart < 5000;
      if (sameWindow) {
        current += shift.value;
      } else {
        windows += 1;
        current = shift.value;
        windowStart = shift.time;
      }
      lastTime = shift.time;
      cls = Math.max(cls, current);
    }
    
    console.log(windows);
    console.log(cls.toFixed(2));
    console.log(total.toFixed(2));
    console.log(cls <= 0.1 ? "good" : cls <= 0.25 ? "needs improvement" : "poor");
  4. Open questionMiddle

    CrUX shows a product page's LCP at 3.8 s on mobile (75th percentile), but Lighthouse on your laptop reports 1.9 s. How do you find the cause and fix it?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.

  5. Open questionSenior

    A product page has an INP of 450 ms at the 75th percentile. RUM attributes the worst interactions to the variant picker and the "Add to cart" button. How do you diagnose and fix it?

    Think it through first

    Answer out loud or in your head as if you were in an interview, then reveal.