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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <header>
	<div class="banner"><h1> <i class="fas fa-plane"></i> Travel App</h1></div>
</header>
<div class="container">
	<form action="" id="add-place">
		<h2 id="form-header"><i class="fas fa-globe-europe"></i> Add Place</h2>
		<fieldset>
			<label for="country">Country:</label>
			<input type="text" name="country" id="country" placeholder="Type a country name.." required="required" />
		</fieldset>
		<fieldset>
			<label for="city">City:</label>
			<input type="text" name="city" id="city" placeholder="Type a city name..." required="required" />
		</fieldset>
		
		<fieldset>
        <legend>Select If you have visted</legend>
        
			<input type="radio" id="visited" name="choice" value="true"/>
			<label for="visited">Visited</label>

			<input type="radio" id="unvisited" name="choice" checked value="false"/>
			<label for="unvisited">Unvisited</label>
        
    </fieldset>
		<fieldset>
			<label for="fav">Favourite:</label>
			<input type="checkbox" name="fav" id="fav" checked>
		</fieldset>
		<fieldset>
			<label for="date">Date if Visited:</label>
			<input type="date" name="date" id="date">
		</fieldset>
		
		<fieldset>
			<label for="image">Image URL:</label>
			<input type="text" name="image" id="image" placeholder="add an image url.." required="required" />
		</fieldset>
		
		<input type="submit" id="submit" value="Add to list" />
	</form>
	
	<div class="placesContainer">
		<h3>My Places</h3>
		<p class="noplacesAdded">Nothing added yet!</p>
		<div class="my-places">
				<!-- places get added here	 -->
		</div>
	</div>
</div>
<footer>
	<small>Designed and Developed with hand-coded Love by Aimee &hearts; 2018</small>
</footer>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Do+Hyeon|Lato:400,700');
html {
	font-size: 10px;
	box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: inherit;
}

body {	
	font-family: 'Lato', sans-serif;
	color: black;
	font-size: 2rem;
	background: #d1d1d1;
}

h1, h2, h3 {
	font-family: 'Do Hyeon', sans-serif;
	margin: 0;
	padding: 0;
}
header {
	color: white;
	text-align: center;
	padding: 3rem;
	background-color: black;
}
.container {
	width: 90%;
	margin: 0 auto;
}


#add-place {
	width: 100%;
	background-color: #e5e5e5;
	padding: 2rem;
	
	#form-header {
		background-color:black;
		color: white;
		height: auto;
		padding: 2rem;
	}
	label {
		font-size: 1.6rem;
		font-weight: bold;
	}
	
	input:focus {
		outline: 2px solid #a4d4a4;
	}
	input[type='text'], input[type='date'] {
		width: 100%;
		margin: .5rem 0;
		padding: .5rem;
		border:none;
	}
	input[type='radio'] {
		padding: 0 3rem;
	}
	fieldset {
		border: 1px dashed #a4d4a4;
		margin: 2rem 0;
	}
	input[type='submit'] {
		border:none;
		padding: 1rem 2rem;
		background-color: #a4d4a4;
		color: white;
		transition: all .5s ease-out;
		
		&:hover {
			background-color: darken(#a4d4a4, 20%);
		}
	}
}

// PLACES CONTAINER ====
.placesContainer {
	background-color: white;
	padding: 2rem;
	
	h3 {
		margin-bottom: 1em;
	}
}

.my-places {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	grid-gap: 2em;
	
	.place {
		border: 2px solid #a4d4a4;
		padding: 1rem;
		max-width: 400px;
	}
	
	img {
		width:100%;
	}
	
}


footer {
	background-color: silver;
	padding: 3rem;
	text-align: center;
	
	small {
		font-size: 1.2rem;
	}
}
              
            
!

JS

              
                let submitFormData = document.querySelector('#submit');
let radioBtns = document.getElementsByName('choice');
let myPlaces = document.querySelector('.my-places');
let placesPara = document.querySelector('.noplacesAdded');

// VARS 
let country, image, city, date, fav, radioChoice, reverseDate, wantToGo;

// function that loops Radio buttons and gets the checked one for vitisted of unvisited.
function getRadioValue() {
	let choice;
		 radioBtns.forEach((btn)=>{
			if(btn.checked){
				 choice = btn.value;
				//console.log(`your choice is ${choice}`);
				}
		});
	return choice;
}


// LocalStorage is not enabled in CodePen for security reasons ====
// Check Local Storage for Data on Page Reload or use empty array.
// let allEntries = JSON.parse(document.localStorage.getItem("allEntries")) || [];
let allEntries = [];

// LocalStorage is not enabled in CodePen for security reasons ====
// CHECK IF THERE IS ANYTHING IN LOCAL STORAGE!!! ====
// if(document.localStorage.getItem("allEntries") !== null){
	// console.log('entries in localstorage');
	
	/// Loop through the array of entries to display on the Screen...
	allEntries.map((entry, i) => {
		
		const {country, city, fav, imageUrl, visited, date} = entry;
		// - hide paragraph saying no places.
		placesPara.style.display = 'none';
		wantToGo = `${visited === 'Been' ? true : false}`;
		
		let content = `<section class="place">
								<img src="${imageUrl}" / alt="photo">
								<p><span class="country">Country: ${country}</span><br/>
								<span class="city">City: ${city}</span></br>
								<span class="fav">${fav ? 'Favourite: ❤️' : ''}</span></br>
								<span class="wanttogo">Visited/Unvisted: ${visited ? 'Been' : 'Wish'}</span></br>
								<span class="date"> ${visited ? '<span class="date">Date Visited:' + ' ' + date + '</span>' : ''}</span></br>
								</p></section>`
		// adding the new content each time added to the existing content.
			myPlaces.innerHTML += content;	
	})
 // }

// ADDING PLACE FUNCTION =============
function placeAdded() {
		// - hide paragraph saying no places.
		placesPara.style.display = 'none';
		// // create a new section -----
		
		let content = `<section class="place">
								<img src="${image}" / alt="photo">
								<p><span class="country">Country: ${country}</span><br/>
								<span class="city">City: ${city}</span></br>
								<span class="fav">${fav ? 'Favourite: ❤️' : ''}</span></br>
								<span class="wanttogo">Visited/Unvisted: ${wantToGo ? 'Been' : 'Wish'}</span></br>
								${wantToGo ? '<span class="date">Date Visited:' + ' ' + reverseDate + '</span>' : ''}
								</p></section>`
		// adding the new content each time added to the existing content.
			myPlaces.innerHTML += content;	
}


// LocalStorage is not enabled in CodePen for security reasons ====
// SORT OUT ADDDING AND ARRAY THAT STAYS UPDATED AND DOESN'T Empty on refresh...
// Add data to localStorage ----
// function addLocalStorage(arr) {
// 	document.localStorage.setItem("allEntries", JSON.stringify(arr));
// }

//Check Errors of Form ===
 function errorCheck(){
	 if(document.querySelector('#country').value == "" || document.querySelector('#city').value == "" || document.querySelector('#image').value === "") {
		 console.log('these fields are required!')
	 }
 }

// Getting Values from Add Place Form =============
submitFormData.addEventListener('click', (e) => {
		
	errorCheck()
	e.preventDefault();
	country = document.querySelector('#country').value;
		city = document.querySelector('#city').value;
		date = document.querySelector('#date').value;
		image = document.querySelector('#image').value;
		
		//Split the Date by the -, so you get an array of year, month, day
		let splitDate = date.split("-"); 
		// then reverse the array, so you will get a date
   	reverseDate = splitDate.reverse(); 
		
		// call function to check if been or wish for visited.
		radioChoice = getRadioValue();
		wantToGo = radioChoice === 'true' ? true : false;
		fav = document.querySelector('#fav').checked;
		
		let entry = {
			country: country,
			city: city,
			visited: wantToGo,
			fav: fav,
			date: reverseDate,
			imageUrl: image
		}
		// allEntries.push(entry);
		// function that added data to DOM
		placeAdded();
		
		// LocalStorage is not enabled in CodePen for security reasons ====
		// Add to local storage function
		// addLocalStorage(allEntries);
})


              
            
!
999px

Console