Back to Freecodecamp

Challenge 168: Scaled Image

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/696655d24b614176d4c9b78b.md

latest1.1 KB
Original Source

--description--

Given a string representing the width and height of an image, and a number to scale the image, return the scaled width and height.

  • The input string is in the format "WxH". For example, "800x600".
  • The scale is a number to multiply the width and height by.

Return the scaled dimensions in the same "WxH" format.

--hints--

scaleImage("800x600", 2) should return "1600x1200".

js
assert.equal(scaleImage("800x600", 2), "1600x1200");

scaleImage("100x100", 10) should return "1000x1000".

js
assert.equal(scaleImage("100x100", 10), "1000x1000");

scaleImage("1024x768", 0.5) should return "512x384".

js
assert.equal(scaleImage("1024x768", 0.5), "512x384");

scaleImage("300x200", 1.5) should return "450x300".

js
assert.equal(scaleImage("300x200", 1.5), "450x300");

--seed--

--seed-contents--

js
function scaleImage(size, scale) {

  return size;
}

--solutions--

js
function scaleImage(size, scale) {
  const [width, height] = size.split("x").map(Number);

  const newWidth = width * scale;
  const newHeight = height * scale;

  return `${newWidth}x${newHeight}`;
}