Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!--- 3
Turning sun into moon-->
<div id="world">
	<div id="sun">
		<div class="sunbeams">
		  <div class="beam beam1"></div>
		  <div class="beam beam2"></div>
		  <div class="beam beam3"></div>
		  <div class="beam beam4"></div>
		  <div class="beam beam5"></div>
		  <div class="beam beam6"></div>
		  <div class="beam beam7"></div>
		  <div class="beam beam8"></div>
		</div>
		<div class="eyes">
			<div class="eyes-l"></div>
			<div class="eyes-r"></div>
		</div>
     <div id="moon">
		<div class="crater crater1"></div>
		<div class="crater crater2"></div>
		<div class="crater crater3"></div>
		<div class="crater crater4"></div>
		<div class="crater crater5"></div>
		<div class="crater crater6"></div>
		
	</div>
	</div>
</div>



              
            
!

CSS

              
                body {
	width:100%;
  height:100%;
	margin:0;
	padding:0;
	background-color:#eee;
  transition: background-color 0.5s ease;
  padding-bottom:100px;
  text-align:center;
}
#world {
	width:400px;
	height:400px;
	display: inline-block;
	position:relative;
	overflow:hidden;
	transition: border 0.5s ease;
}
#sun {
	height: 200px;
	width: 200px;
	background: #F7971E;  /* fallback for old browsers */
  border-radius: 50%;
	display: inline-block;
	position:absolute;
	top:50px;
	left:90px;
	border:5px solid #7a6021;
	transition: top 0.1s ease;
}

.beam {
	width:5px;
	height:30px;
	background:#7a6021;
	position:absolute;
}

.beam1 {
	transform: rotate(0deg);
	top:-20px;
	left:120px;
}
.beam2 {
	transform: rotate(45deg);
	top:20px;
	left:220px;
}
.beam3 {
	transform: rotate(90deg);
	top:110px;
	left:250px;
}
.beam4 {
	transform: rotate(135deg);
	top:200px;
	left:220px;
}
.beam5 {
	transform: rotate(180deg);
	top:240px;
	left:120px;
}
.beam6 {
	transform: rotate(225deg);
	top:200px;
	left:20px;
}
.beam7 {
	transform: rotate(270deg);
	top:110px;
	left:-10px;
}
.beam8 {
	transform: rotate(315deg);
	top:20px;
	left:20px;
}
.sunbeams {
    width: 250px;
    height: 250px;
    position: absolute;
    top: -25px;
    left: -25px;
    animation: spin 28s linear 0s infinite;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
@keyframes blink {
    0% { height: 15px; top:0; }
    99% { height: 15px; top:0; }
    100% { height: 0px; top:7px; }
}
.eyes {
    position: absolute;
    width: 110px;
    height: 20px;
    top: 90px;
    left: 45px;
}
.eyes-l {
	width:15px;
	height:15px;
	border-radius:50%;
	position:absolute;
	top:0;
	left:0;	
    animation: blink 7s linear 0s infinite;
}
.eyes-r {
	width:15px;
	height:15px;
	border-radius:50%;
	position:absolute;
	top:0;
	right:0;
    animation: blink 7s linear 0s infinite;
}

#sun .eyes-l, #sun .eyes-r {
	background:#4f0504;
}
.crater {
	position:absolute;
	border-radius:50%;
	background:#30302D;
}
.crater1 {
	width:30px;
	height:30px;
	top:40px;
	left:40px;
}
.crater2 {
    width: 15px;
    height: 15px;
    top: 20px;
    left: 110px;
}
.crater3 {
    width: 25px;
    height: 25px;
    top: 50px;
    left: 150px;
}
.crater4 {
	width: 35px;
	height: 35px;
	top: 130px;
	left: 30px;
}
.crater5 {
	width: 25px;
    height: 25px;
    top: 160px;
    left: 100px;
}
.crater6 {
	width: 20px;
    height: 20px;
    top: 140px;
    left: 150px;
}
#moon{
  visibility: hidden;
}
              
            
!

JS

              
                ///////////////////////////////// Exercises ////////////////////////////////

//1

// Write a function named "welcome" that takes a name as a parameter and returns the sentence "Welcome, ________!" printed to the console, where the name passed in as an argument is in the blank.
 
  // Pass in 3 different arguments and check that the three sentences are printed to the console.


//2

// Write a JS function that takes a number and returns the number printed to the console in reversed order.

  // Call the function 5 times with 5 different arguments

  // Ex: Passing in 12345 as an argument for the function, I should get 54321 returned 


//3

  // For the next exercise, you will turn the cute sun animation into a cute moon animation using JavaScript only 
 
    //3.1: Declare a new object named 'moon' using the 'let' keyword.

    //3.2: Give the object the following properties and values:

      // 1. Property: color

        //  Value: gray


      // 2. Property: border

        // Value: solid blue border with a width of 5 pixels

        // hint: a dashed red 1 pixel border is programmed in CSS shorthand like so: "1px dashed red"


      // 3. Property: editSun

         // Value: method that returns the div with the id of "sun" by using the querySelector method in the return statement

         // When we invoke the editSun method, it will act as a selector for the #sun div


    //3.3: Using the sun object's editSun method, change the background color of the sun to gray

    // hint: use the moon object's editSun method to select the sun div, and then assign attributes to the values of the moon object's other properties

      // we can then use the CSS style method to alter attributes, 

        // ex: document.querySelector("#ID").style.backgroundColor = "red";
        // ex: document.querySelector("#ID").style.border = "blue";


    //3.4 Finally, use the query selector method to select the 'sunbeams' class

            // Assign the sunbeams class's style.display attribute to 'none' to make the sunbeams stop showing

         // Use the query selector method to select the div with the #moon id

            // Use the style.visibility attribute to assign the value of 'visible' to the craters

  // Credit to Adam Walker for the sun pen: https://codepen.io/renduh/pen/pKQYZw

              
            
!
999px

Console