Local Weather, can't assign styles to the background images via classList.add() method [CLOSED]

Hi Guys,
I am trying to assign the styles of ‘bg’ class to the background images but it is not working.
Could someone help what’s wrong in my code?


I just looked at your pen, but do not see the Switch statement shown in your screenshot.


Codepen’s Autosave… :tired_face:

Sorry @RandellDawson, the code was erased…

You can skip adding the bg class, but you will need to modify your css as follows:

html,body {
  font-family: 'Skranji', cursive;
  font-size: 18px;
  height: 100%;
  width: 100%;
  background-size: cover;
  background-repeat: no repeat;
  background-position: center center;

Then your switch statement will need to look like:

    switch (weatherType) {
      case "Clear":
        document.body.style["background-image"] =
1 Like

Thanks for the answer @RandellDawson. I have one more question, pls.

My last issue is that I would like the background image to fit width, height and should auto-scale in proportion.

This is the photo in large screen devices

and this the photo in other screen devices
I would like the second option to be on all screen devices. Do you have any idea, what can I do?
This is my css:

* {
  margin: 0;
  padding: 0;

body {
  font-family: 'Skranji', cursive;
  font-size: 18px;
  background-size: cover;
  background-position: center;
  min-height: 100vh;