I have a function that averages all of the values from multiple sliders. I am trying to take the data I get from that average and insert into the tweet. Example: "I just scored 100 points playing this awesome game!" The point value obviously being changed dynamically based on the average value. I am very new to Javascript/Jquery so please include extreme amounts of details when answering. Thanks! Here is my Jquery:
$(function readTweet() {
$(document).ready(function () {
console.log($(".tweet").text());
});
$(function(average) {
var numberOfRatings = $(".rating").length,
average;
$( ".slider" ).slider().find(".ui-slider-handle").addClass("custom");
$( ".slider" ).slider({
range: "min",
value: 5,
min: 1,
max: 10,
slide: function( event, ui ) {
var total = 0;
$(this).siblings( ".rating" ).text(ui.value);
$(".rating").each(function () {
var ratingValue = parseInt($(this).text(), 10);
total = parseFloat(total + ratingValue);
console.log(ratingValue);
});
average =(total/numberOfRatings).toFixed(2);
$("#average").text(average);
$(".tweet").click(function (){
$(this).html("I just scored " + average + "points playing this awesome game!");
});
}
});
$( ".rating" ).text($( ".slider" ).slider( "value" ) );
$(".ui-slider-handle").focus(function() {
$(this).removeClass("ui-state-hover ui-state-default ui-state-focus ui-state-active");
});
});
});
HTML
<div id="grand-total">
<h1>Album Rating</h1>
<h2 type="text" id="average" value="0">0</h2>
<a href="https://twitter.com/intent/tweet?" class="twitter-mention-button tweet">Tweet to </a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>