Cookie Consent by Free Privacy Policy Generator 📌 EV Test Drive Project


✅ EV Test Drive Project


💡 Newskategorie: Programmierung
🔗 Quelle: dev.to

Electric Car Website Project

Step 1 : Coming up with an idea

Purpose:

  • As someone interested in new technology and cars, I want to have the users to get information about the Electric vehicles and their qualities that they need
  • I want this site to give accessibility to get them book a test drive when the customer's see the car that they want.
  • Since in today's world there is a pletora of option to choose from. I want to give users the option to randomly get a car that they can test drive.

Requirements

  • Have a webrowser installed.
  • Have a code editor installed.
  • Have json-server installed in the code editor.

Installation Instructions

  1. Fork and clone.https://github.com/AricayaJohn/EVTestDrive-Project
  2. Run json-server --watch db.json in code Editor.
  3. Open index.html in the browser.

Step 2: Features

- I want to have a title in the header.
To do this, in the HTML add h1 tag in the body of the file.

<h1 id = "header">Electric Car Test Drive</h1>

- I want to have a random button generator.
To do this, we add a button tag with an id attribute in html.

 <button id = "randomBtn">Random EV</button>

-I want a list of cars with its information inside a card structure that can also take a user information so that they can book the test drive. (DOMContentLoaded)
To do this we will create a div element with id attribute and a class attribute that will allow us to edit, style and manipulate the data in html.

  <div id ="ev-collection" class = "card-containter"></div>
    <!--This where we will fetch data from db.json then create a card in js-->
        </div>

Step 3 : Come up with an MVP

  • I want a list of cars inside a card structure. (DOMContentLoaded) To do this, we are going to fetch the data using DOMCOntentLoaded event listener and use a function to call and create the cards from our the data in our json file.
document.addEventListener("DOMContentLoaded", () => {
    fetchGetEVData();
    createRandomBtn(); // call the function for random button 
})
//This is to get data from db.json
function fetchGetEVData() {
    fetch("http://localhost:3000/EV")
    .then(resp => resp.json())
    .then(data => {
      console.log("Data fetched successfully:", data); // Log fetched data json objects to console
            data.forEach(EV => showCars(EV));
        })
        //if promise failed to load data from json file
        //then it will show error 
        .catch(error => {
          console.error('Error fetching the json data', error)
        })
    }
  //Create a card
function showCars(EV) {
  //Fetch data for ev-collection HTML and create structure to cards
    const evCollection = document.getElementById("ev-collection");
        const div = document.createElement("div")
        div.classList.add("card");
  //Create images variable to add to div 
    const img = document.createElement("img")
        img.src = EV.ImageLink
        img.classList.add("car-img")

 //Create h2 variable to give title for card
    const h2 = document.createElement("h2")
    h2.textContent = EV.Company

 //Create p document for model, price, and range
    const p = document.createElement("p")
        p.textContent = EV.Model

 //Create p for price 
    const price = document.createElement("p")
        price.textContent = EV.Price  

 //create p for range
    const range = document.createElement("p")
        range.textContent = EV.Range
  • I want to take user information into a form so that they can book the test drive In our index.js, below of our previous syntax we will create a form variable that will contain alabel and input for name, email, and date of testdrive and a submit button for the form
 //Create a form for user's info name, email, the day to test drive, and submit button
    const form = document.createElement("form")
        form.classList.add("comment-form")
 //Create a label for name
        const userName = document.createElement("Label")
            userName.textContent = "Name: ";
            const userInput = document.createElement("input")
            userName.type = "text"
            userInput.name = "name";
  //Create a label for email          
        const userEmail = document.createElement("label")
            userEmail.textContent = "Email: ";
            const inputEmail = document.createElement("input")
            inputEmail.type = "email";
            userEmail.name = "email";
 //Create a email label and input
        const dateLabel = document.createElement("label")
        dateLabel.textContent = "Schedule Test Drive: "
        const dateInput = document.createElement("input")
        dateInput.type = "date";
        dateInput.name = "date";
 //Create a submit button to submit form 
        const submitBtn = document.createElement("input")
        submitBtn.type = "submit"
        submitBtn.value = "submit"
 //Handling submit function eventListener
            function handleSubmit(event) {
                event.preventDefault();
                const name = userInput.value;
                const email = inputEmail.value;
                const date = dateInput.value;
                if (!name || !email || !date) {
                    alert("Please complete all fields before submitting the form.");
                    return;
                  }

                alert("Your Test Drive reservaton has been completed");
                form.reset();  
            };
    //callback
    form.addEventListener("submit", handleSubmit)

Then we will append this functions, attributes and elements to the Dom so that we could see it on our website.

//Going to append the form to the card DOM
    form.appendChild(userName);
    form.append(userInput);
//Create a break to have another input bellow
    form.appendChild(document.createElement("br"))
//Going to append the email form to the card DOM    
    form.appendChild(userEmail);
    form.append(inputEmail);
//Going to create a break to put date label and input bellow
    form.appendChild(document.createElement("br"))
//Going to append date label and input to the DOM
    form.appendChild(dateLabel)
    form.append(dateInput);
//Adding a break to put submit button bellow 
    form.appendChild(document.createElement("br"))
//Appending submit button to form 
    form.appendChild(submitBtn)

//Connect the data to html div to be able to send to the DOM       
div.append (img, h2, p, price, range, form)
    evCollection.append(div)
}

*- I want to have a random button generator that would pick a random car for the user. *

To do this, we are getting the randomBtn tag in our HTML and adding a function to it so that it would display a random EV card.

function createRandomBtn() {
    const randomBtn = document.getElementById("randomBtn");
    randomBtn.classList.add("random-btn");

    randomBtn.addEventListener("click", () => {
      const cards = document.querySelectorAll(".card");
      const randomIndex = Math.floor(Math.random() * cards.length);

      cards.forEach((card, index) => {
        if (index === randomIndex) {
          card.style.display = "block"; // Show the selected card
        } else {
          card.style.display = "none"; // Hide the other cards
        }
      });
    });
  }

**- I want an alert to show up when form is submitted or is incomplete. **
To do this, we add a function and event listener bellow our submit button that we created.

 //handling submit
            function handleSubmit(event) {
                event.preventDefault();
                const name = userInput.value;
                const email = inputEmail.value;
                const date = dateInput.value;
                if (!name || !email || !date) {
                    alert("Please complete all fields before submitting the form.");
                    return;
                  }

                alert("Your Test Drive reservaton has been completed");
                form.reset();  
            };
    form.addEventListener("submit", handleSubmit)

Step 4 : Stretch goals

  • I want to have a drop down button that filters down to the car model
  • I want user can like/favorite the vehicle (click)
  • Add form for user to submit a test drive request to their email at certain date
...

✅ Giving Project Astra a little test drive. 🏎️This demo was shot in a single take, in real time.


📈 16.36 Punkte

✅ EV Test Drive Project


📈 16.36 Punkte

✅ How to keep the Google Drive desktop client from using up your hard drive space


📈 14.84 Punkte

✅ VB2018 preview: From drive-by download to drive-by mining


📈 14.84 Punkte

✅ If I had a computer with only a thumb drive as it's hard drive, how exactly does booting from that work?


📈 14.84 Punkte

✅ Removing OS from hard drive so that drive can be used as storage


📈 14.84 Punkte

✅ Way for linux server to transfer files to internal drive then external drive?


📈 14.84 Punkte

✅ Was making partition for a boot drive on a USB drive and this happened...


📈 14.84 Punkte

✅ Can I create a pen drive that boots a Linux distro in a virtual machine that all exist on the pen drive?


📈 14.84 Punkte

✅ [Grub2] Linux on Drive- Boot into Windows when drive not plugged in


📈 14.84 Punkte

✅ Create Kali Bootable Installer USB Drive in Windows 10 (Kali Bootable Non-Persistence USB Drive)


📈 14.84 Punkte

✅ If I install linux on a flash drive can I still use the same flash drive for storage?


📈 14.84 Punkte

✅ TIFU: I installed openSUSE on my storage drive not my boot drive.


📈 14.84 Punkte

✅ luks encrypting a new hard drive prior to OS installation vs full drive encryption during OS install?


📈 14.84 Punkte

✅ Die Google Drive Desktop-App wird eingestellt: Backup and Sync & Drive File ...


📈 14.84 Punkte

✅ Does new hard drive have any old data or traces of old hard drive?


📈 14.84 Punkte

✅ From hard drive to over-heard drive: Boffins convert spinning rust into eavesdropping mic


📈 14.84 Punkte

✅ Google Backup & Drive endet bald: Wie Sie Ihre Daten zu Drive transferieren


📈 14.84 Punkte

✅ Was unterscheidet Angriffe per Drive-by Login und Drive-by Download?


📈 14.84 Punkte

✅ Linux on a flash drive or hard drive?


📈 14.84 Punkte

✅ From hard drive to over-heard drive: Boffins convert spinning rust into eavesdropping mic


📈 14.84 Punkte

✅ Google Drive: Sicherheitsupdate wird ältere YouTube- und Drive-Links aufheben


📈 14.84 Punkte

✅ Was unterscheidet Angriffe per Drive-by Login und Drive-by Download?


📈 14.84 Punkte

✅ Google Fotos & Google Drive: So lassen sich Fotos & Video von Google Drive zu Google Fotos übertragen


📈 14.84 Punkte

✅ A native G. Drive Linux Laptop and no a native G. Drive Linux Client....


📈 14.84 Punkte

✅ How to Mount Google Drive Account in Ubuntu 18.04 Using Google Drive Ocamlfuse


📈 14.84 Punkte

✅ Synology Drive Server 2.0 und neuer Synology Drive final erschienen


📈 14.84 Punkte

✅ Policies tab missing for External Drive or USB drive on Windows 11


📈 14.84 Punkte

✅ How to Mount Google Drive Account in Ubuntu 18.04 Using Google Drive Ocamlfuse


📈 14.84 Punkte

✅ VB2018 paper: From drive-by download to drive-by mining: understanding the new paradigm


📈 14.84 Punkte











matomo

Datei nicht gefunden!