How would I calculate reading speed?


(Alessandro) #1

Hello everyone
I need a script that counts the number of words read per minute.
The user enters the number of words of the text in a field. In another adds the time it takes to read it, it expressed in minutes.

By clicking on a button, the result must be released

The basic example is this, but how can I implement it in hype3?:

var word = $('#parole').val();  //the user write the number
var parSec = word * 60;  //the number written by users is multiplied by 60
var time = $('#tempo').val() ; // users write the time expressed in minutes 
var secTime = time*60 //how to convert the time in second?
var PAM = parSec / secTime ;  // It is divided by the number written in the form, and then multiplied by 60 (Parsec) with the time expressed in minutes (time)
document.getElementById("demo").innerHTML = PAM; //releases the results

Can you help me?
Thanks for your help and cooperation.
Alessandro


#2

Hi @Alessandro63

You can just run this script “on mouse click” providing you have two editable elements (possibly inputs inside the innerHTML) that both have the following ID’s respectively “parole” and “tempo”. Then an element to show the results.

wordSpeed.zip (16.7 KB)


(Alessandro) #3

Hi Dbear
Thank you very much, but the problem persists!
If it is written “2.3” or “2.3” to indicate 0:02:30 (h.m.s) this is equivalent to 150 seconds, but now it is converted at 138 seconds and is logically a mistake.
I’m looking for a simple solution in javascript, to be added to the script!


#4

The question you asked was how to implement it in Hype 3

I have shown you that. :slight_smile: Wherever you have gotten the above script then you should check there to see why it is written this way.

Also the above “script” is in jQuery too. Do you want vanilla Javascript or do you want to use jQuery?

2.3 is a decimal and therefore equates to 138 seconds. If you want the user to input minutes then perhaps you need to find a different way.

Maybe get the users to just write in secs. (i.e convert it themselves) or
create a small function to convert the decimal to secs or get them to input it like this 2:30

That way you can use this function to convert it

function convert(input) {
		var parts = input.split(":");
		var min = Math.floor(parts[0]) * 60;
 		var sec = Math.floor(Math.abs(parts[1]));
 		return min + sec;
	}
	
	hypeDocument.getElementById('result').innerHTML = convert(box.value);

(Fernando) #5

Maybe my template can help you too. Be careful to leave two spaces between paragraphs because it will be a word.
Wordsperminute.hype.zip (15.8 KB)


(Alessandro) #6

Thank you all for your help, I used the example of DBear and the idea of dividing between minutes and seconds, by Fernando (muchas gracias).
You make this forum a real treasure!
Alessandro