-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (25 loc) · 1.12 KB
/
script.js
File metadata and controls
31 lines (25 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* If you're feeling fancy you can add interactivity
to your site with Javascript */
console.log("JS file is loaded!");
// Initialize Firebase ///////////////
var config = {
apiKey: "AIzaSyAdicsEV3qamI6F5aXJc6WRuvAEBHeGWC8",
authDomain: "barry-firebase-test.firebaseapp.com",
databaseURL: "https://barry-firebase-test.firebaseio.com",
projectId: "barry-firebase-test",
storageBucket: "barry-firebase-test.appspot.com",
messagingSenderId: "200692124595"
};
firebase.initializeApp(config);
/////////////////////////////////////////
// Get html element into JS.
let firebaseGreetElem = document.getElementById("firebase-greeting");
console.log(firebaseGreetElem);
// Reference to key-value pair of "greeting"
let dbGreetingRef = firebase.database().ref("greeting");
// Event listener for changes in value in Firebase db.
dbGreetingRef.on("value", displayFirebaseGreeting);
// Change in value will cause new value to appear. Of course, some other function may be defined to run when value changes.
function displayFirebaseGreeting(dataSnapshot) {
firebaseGreetElem.textContent = dataSnapshot.val();
}