Guest User

Untitled

a guest
Mar 23rd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. html:
  2. <p>Alice was a
  3. <select id="behave">
  4. <option value="good">good</option>
  5. <option value="naughty">naughty</option>
  6. </select>
  7. <span class="boygirl">girl</span>.
  8. <span class="plotelement1">
  9. <span class="HeShe">She</span> was constantly being told off by
  10. <span class="hisher">her</span> <span class="mainparent">mother</span>
  11. </span>.
  12. </p>
  13.  
  14. js:
  15. function genderChange(){
  16. var newgender = $("#gender").val();
  17. if(newgender == "male"){
  18. $(".heshe").text("he");
  19. $(".HeShe").text("He");
  20. $(".himher").text("him");
  21. } else {
  22. $(".heshe").text("she");
  23. $(".HeShe").text("She");
  24. $(".himher").text("her");
  25. }
  26. }
  27. function changeBehaviour(){
  28. switch($("#behave").val()){
  29. case "good":{
  30. $(".plotelement1").html('<span class="HeShe">She</span> made <span class="hisher">her</span> parents proud of <span class="himher">her</span> and they told <span class="himher">her</span> all the time how good <span class="heshe">she</span> was.');
  31. break;
  32. }
  33. default:{
  34. $(".plotelement1").html('<span class="HeShe">She</span> was constantly being told off by <span class="hisher">her</span> <span class="mainparent">mother</span>');
  35. }
  36. }
  37. genderChange();
  38. }
  39.  
  40. <p>
  41. <select id="gender">
  42. <option value="male">male</option>
  43. <option value="female">female</option>
  44. </select>
  45. Alice was a
  46. <select id="behave">
  47. <option value="good">good</option>
  48. <option value="naughty">naughty</option>
  49. </select>
  50. <span class="boygirl">girl
  51. </span>.
  52. <span class="plotelement1">
  53. <span class="HeShe">She</span> was constantly being told off by
  54. <span class="hisher">her</span>
  55. <span class="mainparent">mother</span>
  56. </span>.
  57. </p>
  58.  
  59. <script>
  60. function genderChange(){
  61. var newgender = $("#gender").val();
  62. if(newgender == "male"){
  63. $(".heshe").html("he");
  64. $(".HeShe").html("He");
  65. $(".himher").html("him");
  66. $(".hisher").html("his");
  67. } else {
  68. $(".heshe").textContent = "she";
  69. $(".HeShe").textContent = "She";
  70. $(".himher").textContent = "her";
  71. $(".hisher").html("her");
  72. }
  73. }
  74. $(function(){
  75. changeBehaviour();// These 2 lines run after loading the whole page.
  76. genderChange(); //
  77.  
  78. $("#gender").change(function(){
  79. changeBehaviour();// Change the behaviours first
  80. genderChange(); // Then change the gender as the behaviour code has
  81. // gender's span like ".hisher" so this has to be the
  82. // order.
  83. });
  84. $("#behave").change(function(){
  85. changeBehaviour();
  86. genderChange();
  87. })
  88. });
  89. function changeBehaviour(){
  90. switch($("#behave").val()){
  91. case "good":{
  92. $(".plotelement1").html('<span class="HeShe">She</span> made <span class="hisher">her</span> parents proud of <span class="himher">her</span> and they told <span class="himher">her</span> all the time how good <span class="heshe">she</span> was.');
  93. break;
  94. }
  95. default:{
  96. $(".plotelement1").html('<span class="HeShe">She</span> was constantly being told off by <span class="hisher">her</span> <span class="mainparent">mother</span>');
  97. }
  98. }
  99. }
  100. </script>
  101.  
  102. $(".hisher").html("his")
  103.  
  104. <div id="female">
  105. <p id="HE" ></p>
  106. <p id="CAPHIS" ></p>
  107. </div>
  108. <div id="male">
  109. <p id="HIS" ></p>
  110. <p id="CAPHIM" ></p>
  111. </div>
  112.  
  113. function getPronoun(gender, id) {
  114. // array of pronouns to find
  115. var pronouns = ["she", "her", "her", "he", "his", "him"];
  116.  
  117. // array of the last two letters of incoming pronouns in id parameter
  118. var ids = ["HE", "IS", "IM"];
  119.  
  120. // get the index of the ids array matching the last two letters of id parameter
  121. var index = ids.indexOf(id.slice(-2));
  122.  
  123. // if gender parameter is male, add 3 to the index
  124. index = gender == 'male' ? index + 3 : index;
  125.  
  126. // use index to select the proper pronoun from the pronouns array
  127. // and capitalize it if CAP is present in the id parameter
  128. return id.indexOf('CAP') > -1 ? cap(pronouns[index]) : pronouns[index];
  129. }
  130.  
  131. function cap(input) {
  132. return input.charAt(0).toUpperCase() + input.substr(1);
  133. }
Add Comment
Please, Sign In to add comment