0

Please someone tell me what's wrong with my code.

<script> var c = document.getElementById("siya"); var ctx = c.getContext("2d"); ctx.font = 30px italic; ctx.fillText("Hello World!" 10, 50); ctx.font = 30px italic; //Create gradient var gradient = createLinearGradient(0, 0, c.width, 0); gradient.addColorStop("0", "gray"); gradient.addColorStop("0", "blue"); gradient.addColorStop("0", "black"); //Fill with gradient ctx.fillStyle = gradient; ctx.fillText("Khumalo”, 10, 50); </script>

24th Nov 2018, 2:14 PM
Whisper
Whisper - avatar
5 Answers
+ 7
Italic is not a type of font, try Verdana or something. ctx.font= "30px Helvetica "; Please, always try to include code so we can see the error.
24th Nov 2018, 5:16 PM
dρlÏ…Ń•ÏlÏ…Ń•
dρlÏ…Ń•ÏlÏ…Ń• - avatar
+ 3
There are more problems with the code. ctx.font = 30px italic; -> wrong font type and missing quotation mark ctx.fillText("Hello World!" 10, 50); -> a missing comma gradient.addColorStop("0", "gray"); gradient.addColorStop("0", "blue"); gradient.addColorStop("0", "black"); -> wrong numbers, must be different ctx.fillText("Khumalo", 10, 50); -> wrong closing quotation mark (and the same position as above) See here: https://code.sololearn.com/Wi3m5cAiDGVC/?ref=app https://code.sololearn.com/WOFbIqIPAbuF/?ref=app
24th Nov 2018, 5:52 PM
dozule
dozule - avatar
+ 2
one problem is that 30px italic should be between quotes.
24th Nov 2018, 2:34 PM
Bebida Roja
Bebida Roja - avatar
+ 1
Thank you guys I really appreciate it
25th Nov 2018, 6:01 PM
Whisper
Whisper - avatar
0
Thanks but still it is only displaying border not text
24th Nov 2018, 2:40 PM
Whisper
Whisper - avatar