<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-analytics.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyBqHAqkn8hCZt8WVsot9eg7ifzycgV1Acw",
authDomain: "to-do-list-3ee68.firebaseapp.com",
databaseURL: "https://to-do-list-3ee68-default-rtdb.firebaseio.com",
projectId: "to-do-list-3ee68",
storageBucket: "to-do-list-3ee68.appspot.com",
messagingSenderId: "362512451257",
appId: "1:362512451257:web:24f5b612c55a163b01bd68",
measurementId: "G-CG8HCTLWY6"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db = getFirestore();
</script>
<script src="./script.js"></script>
this is cdn of firebase and i made script.js file like below.
function addItem(event){
event.preventDefault();
let text=document.getElementById("todo-input");
db.collection("todo-items").add({
text: text.value,
status: "active"
});
}
but i got an error like this. i want to know why i can't use the variable "db".
Uncaught ReferenceError: db is not defined at addItem (script.js:4:3) at HTMLFormElement.onsubmit (index.html:56:41)