ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions

Higher Computing Science 2021 Question 14

3 marks · JavaScript mouse events

Write an additional JavaScript function to change the colour of Sale now on to black. Re‑write the paragraph element to include a call to your function from part (a), so that the text can also be changed to black when the mouse moves away. The HTML code and JavaScript function below changes the colour of text when the mouse moves over it. <script> function displayRed(my_text) {my_text.style.color='red';} </script> <p onmouseover="displayRed(this)">Sale now on</p>

Marking scheme

• Appropriate function name with parameter in brackets and subsequent use of parameter for colour change to black Example answer function displayBlack(my_text) { my_text.style.color="Black" ; } • Add onmouseout event to element • Match function name to name created in part (a) 1 mark for each bullet Example answer <p onmouseover="displayRed(thi s)" onmouseout=" displayBlack (this)" > Sale now on</p>

Previous question: Higher Computing Science 2021 Question 13

Next question: Higher Computing Science 2021 Question 15