如何使用var作为单例的频率? [英] How to use a var as a frequency with simpletones?

查看:71
本文介绍了如何使用var作为单例的频率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够输入用户输入的号码:



  <  输入    type     =  number    id     =  投注    min     =  0    max     =   42       =  6 >  





并将其用作playTone的频率( )使用simpleTones.js:



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





我尝试过:



我已经尝试过使用一些simpleTones代码来看看我是否可以改变它的行为方式但是作为一个js初学者我不是很确定要开始。作为参考,这里是我认为可能相关的源代码片段:



 playTone =(频率,类型,持续时间)= > {
if (type === undefined ){
type = 正弦;
}
if (duration === undefined ){
duration = 1 3 ;
}
if (频率=== undefined ){
frequency = 440 ;
}

解决方案

使用parseInt计算出来!



 function playBets(){

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

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

}


I would like to be able to take a user inputted number:

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



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

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:

playTone = (frequency, type, duration) => {
	if (type === undefined) {
		type = "sine";
	}
	if (duration === undefined) {
		duration = 1.3;
	}
	if (frequency === undefined) {
		frequency = 440;
	}

解决方案

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)

	}


这篇关于如何使用var作为单例的频率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆