Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import React, { useState } from 'react'; import { View, Text, StyleSheet, Button } from 'react - native'; import { Picker } from ' @react

import React, { useState } from 'react';
import { View, Text, StyleSheet, Button } from 'react-native';
import { Picker } from '@react-native-picker/picker';
export default function Category1(){
const [selectedFruit, setSelectedFruit]= useState('select');
const [selectedQuantity, setSelectedQuantity]= useState('0');
const [totalPrice, setTotalPrice]= useState(0);
const fruitPrices ={
apple: 12,
banana: 23,
orange: 13,
grapes: 34,
mango: 15,
};
const vegetablePrices ={
potato: 5,
carrot: 8,
tomato: 5,
cucumber: 7,
spinach: 8,
};
const addToBasket =()=>{
const price = fruitPrices[selectedFruit]|| vegetablePrices[selectedFruit];
const subtotal = price * parseInt(selectedQuantity);
const newTotalPrice = totalPrice + subtotal;
setTotalPrice(newTotalPrice);
console.log(`Adding ${selectedQuantity} ${selectedFruit}(s) to the basket. Total cost: $${newTotalPrice}`);
};
return (
Fruits
setSelectedFruit(itemValue)}
style={styles.picker}
>
Vegetables
setSelectedFruit(itemValue)}
style={styles.picker}
>
Quantity
setSelectedQuantity(itemValue)}
style={styles.picker}
>
{[...Array(10).keys()].map((i)=>(
))}
Total Price: ${totalPrice.toFixed(2)}
);
}
const styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center',
padding: 20,
backgroundColor: '#ecf0f1',
borderColor: '#ecf0f1',
},
title: {
fontSize: 20,
fontWeight: 'bold',
textAlign: 'center',
paddingVertical: 10,
},
picker: {
width: '100%',
height: 50,
borderColor: '#ccc',
borderWidth: 1,
marginVertical: 10,
},
totalPrice: {
fontSize: 20,
fontWeight: 'bold',
textAlign: 'center',
paddingVertical: 10,
},
});
This code is perfect on snack expo but I need the vegetable dropdown to be first instead of the fruits dropdown.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions