wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let val = 65; val += 1;
let mut val = 65; val += 1;
Need mut to modify.
Rust
cin >> result;
int result; cin >> result;
Declare variable.
C++
data[54]
if data.indices.contains(54) {{ data[54] }}
Check index.
Swift
["result", 9]
["result", 9]
Correct.
JSON
if (foo = 32)
if (foo == 32)
Use ==.
Scala
if x = 5 then print('output') end
if x == 5 then print('output') end
Use ==.
Lua
<?php // code ?>
<?php // code ?>
Correct.
PHP
jwt.sign({{id:46}}, 'key');
jwt.sign({{id:46}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
assert item > 77
assert item > 77
Correct.
Python
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
let result: number = 'hello';
let result: string = 'hello';
Fix type.
TypeScript
function render(): void {{ return 53; }}
function render(): number {{ return 53; }}
Return type mismatch.
TypeScript
math.sqrt(89)
import math math.sqrt(89)
Import module first.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
switch(z){{ case 24: break; }}
switch(z){{ case 24: break; default: break; }}
Add default case.
Java
h1 {{ font-size:90px color:green; }}
h1 {{ font-size:90px; color:green; }}
Add semicolon.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(18);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(18, () => console.log('listening'));
Add callback.
Node.js
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<entry><age>data</age><age>38</age></entry
<entry><age>data</age><age>38</age></entry>
Add closing >.
XML
function process() {{ echo 'world'; }}
function process() {{ echo 'world'; }}
Correct.
PHP
if (result = 45) {}
if (result == 45) {}
Use ==.
Dart
var temp int = 'data'
var temp string = 'data'
Type mismatch.
Go
{{"title":"result" "name":87}}
{{"title":"result", "name":87}}
Add comma.
JSON
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
let y = 57;
let y = 57;
Correct.
JavaScript
local bar = 82
local bar = 82
Correct.
Lua
b > 62 & y < 3
b > 62 and y < 3
Use 'and' not '&'.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<note name='value'/>
<note name="value"/>
Double quotes.
XML
for (count in arr)
for (count of arr)
for...in iterates keys.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'name':60, 'name' 94}}
{{'name':60, 'name':94}}
Colon missing.
Python
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let result: Int = 'message'
let result: String = 'message'
Fix type.
Swift
function foo(val) print(val) end
function foo(val) print(val) end
Correct.
Lua
if x = 40:
if x == 40:
Use == for comparison.
Python
print 'info'
print 'info';
Add semicolon.
Perl
$num = 55; if ($num = 55) {{}}
$num = 55; if ($num == 55) {{}}
Use ==.
PHP
if x = 69
if x == 69
Use ==.
Go
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
INSERT INTO items VALUES ('value',23)
INSERT INTO items (name, email) VALUES ('value',23);
Specify columns.
SQL
yield result
yield result
Correct yield.
Python
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
if z = 76
if z == 76
Use ==.
Ruby
int list[2]; list[2]=5;
int list[2]; if(2<2){{}} else list[2]=5;
Bounds check.
C++
for data in range(99) print(data)
for data in range(99): print(data)
Colon after for.
Python
if z = 77 {{}}
if z == 77 {{}}
Use ==.
Swift
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
while x > 7 x -= 1
while x > 7: x -= 1
Colon missing after while.
Python
print('data')
print('data')
Correct.
R
if item > 59 print('result')
if item > 59: print('result')
Colon missing after if.
Python
if ($val = 41)
if ($val == 41)
Use ==.
Perl
if ($count = 63) {{}}
if ($count -eq 63) {{}}
Use -eq.
PowerShell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
def process(): print('world')
def process(): print('world')
Indent function body.
Python
count = 3
count=3
No spaces.
Shell
val num = 96; num = 66
var num = 96; num = 66
Use var for reassignment.
Scala
let result = 'test'
let result = "test"
Double quotes.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
val foo = 'output'
val foo = "output"
Double quotes.
Kotlin
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
arr[16]
if (length(arr) >= 16) arr[16]
Check length.
R
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:82}};
Add missing property.
TypeScript
'hello' + 58
'hello' + str(58)
Can't add int to string.
Python
let index: number | null = null; index.toFixed(55);
let index: number | null = null; if(index!==null) index.toFixed(55);
Null check.
TypeScript
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
const y;
const y = 50;
Initialize const.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int[] items = new int[58]; items[58] = 5;
int[] items = new int[58]; if (58 < items.length) items[58] = 5;
Check bounds.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
process
process()
Add parentheses.
Kotlin
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
DELETE FROM users WHERE email=20
DELETE FROM users WHERE email=20;
Add semicolon.
SQL
{{'age':'hello'}}
{{"age":"hello"}}
Use double quotes.
JSON
SELECT * FROM orders WHRE email=56;
SELECT * FROM orders WHERE email=56;
Fix WHERE.
SQL
$list[99]
if ($list.Count -gt 99) {{ $list[99] }}
Check bounds.
PowerShell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'97' + 29
97 + 29
Avoid string coercion.
JavaScript
b == '91'
b === 91
Use strict equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
print 'output'
print('output')
print needs parentheses.
Python
<user name='value'/>
<user name="value"/>
Double quotes.
XML
function bar(z) print(z) end
function bar(z) print(z) end
Correct.
Lua
println('message')
println("message")
Double quotes.
Scala
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
{{"name":"world" "status":61}}
{{"name":"world", "status":61}}
Add comma.
JSON
switch(count){{ case 72: break; }}
switch(count){{ case 72: break; default: break; }}
Add default case.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
function compute(b:string){{return b;}} compute(52);
function compute(b:string){{return b;}} compute('info');
Pass correct type.
TypeScript
if foo = 72
if foo == 72
Use ==.
Go
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:36}};
Add missing property.
TypeScript