php variable inside javascript code

This should work:

<?php $script = "<script type="text/javascript">
        jQuery( document ).ready( function($) {         
            $(document).ready(function() {
              $('#particles').particleground({
                dotColor: " . json_encode($dotcolor) . ",
                lineColor: '#5cb9bd',                   
              });
            });
        }
     );
    </script>";
    ?>

Note:
Its a better practice to enqueue Javascripts with wp_enqueue_script() and include dynamic strings via wp_localize_script().

Docs:
https://codex.wordpress.org/Function_Reference/wp_enqueue_script
https://codex.wordpress.org/Function_Reference/wp_localize_script

error code: 523