Tell us what’s happening:
Tests 7-10 keep failing and I don’t understand what I am doing wrong.
It might have to do with the fact that I don’t understand #7 and #8, as in the task.
but I have no idea what #9 and #10’s problems are.
Advice would be greatly appreciated
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Currency Converter</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.3.1/umd/react.development.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.3.1/umd/react-dom.development.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.26.5/babel.min.js"></script>
<script
data-plugins="transform-modules-umd"
type="text/babel"
src="index.jsx"
></script>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="root"></div>
<script
data-plugins="transform-modules-umd"
type="text/babel"
data-presets="react"
data-type="module"
>
import { CurrencyConverter } from './index.jsx';
ReactDOM.createRoot(document.getElementById('root')).render(<CurrencyConverter />);
</script>
</body>
</html>
/* file: index.jsx */
const { useState, useMemo, useRef } = React;
const conversionTable = {
USD: 1,
EUR: 0.92,
GBP: 0.78,
JPY: 156.7,
}
export function CurrencyConverter() {
const [result, setResult] = useState(0);
const [number, setNumber] = useState(0);
const [toCurrency, setToCurrency] = useState("USD");
const [toValue, setToValue] = useState(1);
const [fromValue, setFromValue] = useState(1);
const calculate = useMemo(() => {
let rate = toValue / fromValue;
let value = (number * rate).toFixed(2);
setResult(value);
}, [number, fromValue]);
return (
<>
<input type="number" onInput={(e) => setNumber(e.target.value)}/>
<br/>
<br/>
<label htmlFor="from">From:</label>
<select name="from" id="from" onChange={(e) => setFromValue(conversionTable[e.target.value])}>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="JPY">JPY</option>
</select>
<br/>
<label htmlFor="to">To:</label>
<select name="to" id="to" onChange={(e) => {
setToValue(conversionTable[e.target.value]);
setToCurrency(e.target.value);
}}>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="JPY">JPY</option>
</select>
<p id="result">{result} {toCurrency}</p>
</>
)
}
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:153.0) Gecko/20100101 Firefox/153.0
Challenge Information:
Build a Currency Converter - Build a Currency Converter