Skip to content

Instantly share code, notes, and snippets.

@fehler
Created November 19, 2015 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fehler/19f2014c89c21e64173e to your computer and use it in GitHub Desktop.
Save fehler/19f2014c89c21e64173e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Variables - 02</title>
</head>
<body>
<p>With the money my parents left me I can buy <span id="quantity"></span> cans of <span id="beverage"></span> at a total cost of <span id="totalPrice"></span>.</p>
<script>
var beverage = "Guinness";
var guinnessPrice = 1.20;
var beverage = "Buckfast";
var guinnessPrice = 6.00;
var quantity = 6;
var totalPrice = guinnessPrice * quantity
var totalPrice = buckfastPrice * quantity // This isn't going to work as I have two variables called "totalPrice", we'll need to find another way to do this.
document.getElementById("quantity").innerHTML = quantity;
document.getElementById("beverage").innerHTML = beverage;
document.getElementById("totalPrice").innerHTML = totalPrice;
</script>
</body>
</html>
<!--
Notes
=====
In this example we're defining more values for different beverages. Somehow I need to use variables to calcualte out different prices and quantities. A little stumped. Google is my friend. (So is David Turner!)
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment