Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to be able to take a user inputted number:

HTML
<input type = "number" id = "bets" min = "0" max = "42" value = "6">


And use that as the frequency for playTone() using simpleTones.js:

JavaScript
var bets = document.getElementById("bets"); 
playTone(bets.value, "sine", 6)


What I have tried:

I've tried playing around with some of the simpleTones code to see if I can change the way it behaves but as a js beginner I'm not really sure to start. For reference, here is a snippet of the source I thought might be relevant:

JavaScript
playTone = (frequency, type, duration) => {
	if (type === undefined) {
		type = "sine";
	}
	if (duration === undefined) {
		duration = 1.3;
	}
	if (frequency === undefined) {
		frequency = 440;
	}
Posted
Updated 19-May-18 11:52am

1 solution

Figured it out using parseInt!

function playBets() { 

		var bets = document.getElementById("bets"); 
		bets = parseInt(bets.value) + 440; 

		playTone(440, "sine", 6)
		playTone(parseInt(bets), "sine", 6)

	}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900