jQuery addClass example

Change class name on click in jQuery

HTML

<p>
   <code>window[name]</code> equivalent to dynamically access
   <code>const</code> and <code>let</code> declarations
</p>
<output></output>

CSS

body {
   font-family: system-ui, sans-serif;
   background: lightblue;
   margin: 20px;
   }
output {
   display: block;
   background-color: khaki;
   padding: 10px;
   }

JavaScript

var x = 3;
const y = 7;
let z = 21;

function print(message) {
	$('<div>').text(message).appendTo($('output'));
   console.log(message);
   }
print('x = ' + window['x']);  //x = 3
print('y = ' + window['y']);  //y = undefined
print('z = ' + window['z']);  //z = undefined

// For the above example, how do you get the values 7 and 21
// for "y" and "z" instead of undefined?