0
0
NextJSframework~20 mins

Image optimization with next/image in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js Image Optimization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered output of this Next.js Image component?
Consider this Next.js component using next/image:

import Image from 'next/image';

export default function Avatar() {
  return (
    <Image
      src="/avatar.png"
      alt="User Avatar"
      width={100}
      height={100}
      priority
    />
  );
}

What will the browser display when this component is rendered?
NextJS
import Image from 'next/image';

export default function Avatar() {
  return (
    <Image
      src="/avatar.png"
      alt="User Avatar"
      width={100}
      height={100}
      priority
    />
  );
}
AAn optimized 100x100 pixel image with lazy loading disabled and alt text 'User Avatar'.
BA 100x100 pixel image that loads lazily with no alt text.
CA broken image icon because the src path is invalid.
DAn unoptimized image with width and height ignored.
Attempts:
2 left
💡 Hint
Remember that the priority prop disables lazy loading and improves loading speed for important images.
📝 Syntax
intermediate
2:00remaining
Which option correctly uses the next/image component to fill its parent container?
You want an image to fill its parent container responsively using next/image. Which code snippet is correct?
A<Image src="/photo.jpg" alt="Photo" fill />
B<Image src="/photo.jpg" alt="Photo" layout="fill" />
C<Image src="/photo.jpg" alt="Photo" width="100%" height="100%" />
D<Image src="/photo.jpg" alt="Photo" style={{width: '100%', height: '100%'}} />
Attempts:
2 left
💡 Hint
Check the latest Next.js syntax for filling containers with images.
🔧 Debug
advanced
2:00remaining
Why does this next/image component cause a build error?
Examine this code:

import Image from 'next/image';

export default function Logo() {
  return (
    <Image
      src="https://example.com/logo.png"
      alt="Company Logo"
      width={200}
      height={100}
    />
  );
}

Why might this cause a build error in Next.js?
NextJS
import Image from 'next/image';

export default function Logo() {
  return (
    <Image
      src="https://example.com/logo.png"
      alt="Company Logo"
      width={200}
      height={100}
    />
  );
}
AThe alt prop is missing and required.
BThe width and height props must be strings, not numbers.
CThe src prop cannot use https URLs, only local paths.
DExternal image domains must be added to next.config.js under images.domains.
Attempts:
2 left
💡 Hint
Think about Next.js security and optimization rules for external images.
state_output
advanced
2:00remaining
What happens to the image size when using next/image with sizes prop?
Given this component:

import Image from 'next/image';

export default function Banner() {
  return (
    <Image
      src="/banner.jpg"
      alt="Banner"
      width={1200}
      height={400}
      sizes="(max-width: 600px) 480px, 800px"
    />
  );
}

What effect does the sizes prop have on the rendered image?
NextJS
import Image from 'next/image';

export default function Banner() {
  return (
    <Image
      src="/banner.jpg"
      alt="Banner"
      width={1200}
      height={400}
      sizes="(max-width: 600px) 480px, 800px"
    />
  );
}
AThe image height changes dynamically but width stays fixed.
BThe browser loads a 480px wide image on screens 600px or smaller, otherwise 800px wide image.
CThe sizes prop causes a syntax error and image won't load.
DThe image always loads at 1200px width ignoring sizes.
Attempts:
2 left
💡 Hint
The sizes prop helps the browser pick the best image size based on viewport width.
🧠 Conceptual
expert
2:00remaining
Which statement best explains how next/image optimizes images?
Select the most accurate explanation of how Next.js next/image optimizes images automatically.
AIt requires manual image resizing and format conversion before use.
BIt only lazy loads images but does not change image size or format.
CIt automatically resizes, compresses, and serves images in modern formats based on device and network conditions.
DIt disables caching to always fetch fresh images from the server.
Attempts:
2 left
💡 Hint
Think about what benefits image optimization provides for user experience.