Home HTML Data Types DOM JavaScript JS Debugging

How to use javascript in any of your pages

  • Simply add a <script></script> in your markdown or jupyter cells
  • (Note: the %%html magic command allows us to add HTML and JavaScript into a jupyter notebook, the outputted “site” will be shown below the code)

Writing text to console.log

  • The text written with console.log appears in the Console
  • console.log allows you to write text – but you don’t see any text in above example until you view Console.
  • Activate Console window
    • VSCode Help-Toggle Developer Tools allows you to see console.log output
    • Chrome and other browsers require right click -> inspect also allows access to console.log output
      • Safari users will need to enable developer settings before inspecting an element. To do this go to Safari settings -> advanced and check the box next to “Show develop menu in menu bar”
    • By default you usually need to click Console next to Elements, to see console.log output
    • Also, you may want to press clear console (cirlcl with slash) to clean up screen before analysis.

ccc

  • Write a JavaScript program that compares two variables, a and b. Log “a is greater” if a is greater than b, “b is greater” if b is greater than a, and “both are equal” if a and b are equal. Make sure to use if statements and console.log
%%js

var a = 10;
var b = 5;

if (a > b) {
  console.log("A is greater");
} else if (b > a) {
  console.log("B is greater");
} else {
  console.log("They both are equal");
}

<IPython.core.display.Javascript object>
%%html

<script src="https://utteranc.es/client.js"
        repo="ninaadkiran/Ninaad-Repository2"
        issue-term="pathname"
        theme="github-dark-orange"
        crossorigin="anonymous"
        async>
</script>