התקדמות שלך
41/47

ג'אווה סקריפט המדריך המלא 2024
אובייקטים תרגיל מספר 41 חנות ספרים


בתרגיל ג'אווה סקריפט הבא נלמד איך ליצור חנות ספרים, נלמד איך לעבוד עם מערכים ואובייקטים של ספרים איך ליצור פונקציות שמוסיפות ספרים למערך ואיך ליצור פונקציות שמורידות ומעלות את כמות הספרים מהמערך

  • a. use this user object.
    
    let user = {
       id: "b79fee9d-7001-4618-b58f-8b09fbe4f619",
       name: "doctorcode",
       balance: 1000,
       books: [],
    }
                
  • b. use this books array.
    
    let bookStore = [
        {
            id: 'b79fee9d-7001-4618-b58f-8b09fbe4f615',
            name: 'Davion the knight',
            pages: 1800,
            price: 125.99,
            quantity: 10,
            forKids: false,
        },
        {
            id: 'b79fee9d-7001-4618-b58f-8b09fbe4f618',
            name: 'The Hobbit',
            pages: 2550,
            price: 50.5,
            quantity: 2,
            forKids: false,
        },
        {
            id: 'b79fee9d-7001-4618-b58f-8b09fbe4f622',
            name: 'Lord of the rings',
            pages: 650,
            price: 75.99,
            quantity: 88,
            forKids: false,
        },
    ]
                
  • c. write a CRUD functions,create, read, update and delete a book from the bookStore. createBook() , readBookById() , updateBookById , deleteBookById.
  • d. write a function buyBookById() which reads a book from the store by its id, check if the book has enough copies left and buys it, buy means quantity decreases and user balance and user books property updates accordingly.
שאלות
דברו איתי
whatsapp
ווצאפwhatsapp דיסקורדwhatsapp