Sandbox
Feel free to play around with the example below to see how the web page reacts to your code changes in a consequence-free environment. You won't break or overwrite anything so go for gold.
This project introduces how you can get information from the web page (and the user) to use in your JavaScript.
As with the previous project, you'll use some Svelte-specific code in curly braces { }
.
Specifically, we'll use the bind:value={variableName}
to connect the input in the HTML to a variable in the JavaScript.
Let's compare the jQuery version of The Repeater with the Svelte version.
<label>
Write something:
<input id="txtInput" type="text">
</label>
<button id="btnRepeat">Repeat</button>
<p id="txtOutput"></p>
$('#btnRepeat').click( () => {
let text = $('#txtInput').val()
$('#txtOutput').text('You wrote: ' + text)
})
<script>
let text = ''
</script>
<label>
Write something:
<input bind:value={text}>
</label>
<p>You wrote: {text}</p>
npm install
and then npm run dev
.https://localhost:3000
.<p>Total Cost: {price * 1.15}</p>
Feel free to play around with the example below to see how the web app reacts to your changes in a consequence-free environment.
Feel free to play around with the example below to see how the web page reacts to your code changes in a consequence-free environment. You won't break or overwrite anything so go for gold.